简体   繁体   English

如何使包装纸在特定部分向右流血?

[英]How can I make my wrapper bleed to the right in a particular section?

For a project I have a page where everything is in a wrapper and I scale that wrapper as the screen size gets bigger.对于一个项目,我有一个页面,其中所有内容都在包装器中,并且随着屏幕尺寸变大,我缩放该包装器。 Imagine each box being a section.想象每个盒子都是一个部分。

The middle section bleeds to the right but keeps the same margin to the left as the wrapper does.中间部分向右流血,但在左侧保持与包装器相同的边距。 I don't know the exact width of the the section + the margin on the right and if I do, when it scales it will change.我不知道该部分的确切宽度+右侧的边距,如果我知道,当它缩放时它会改变。 I want the left side to scale inline with the other sections as the browser changes like it does in a regular wrapper.当浏览器像在常规包装器中一样发生变化时,我希望左侧与其他部分内联缩放。

https://codepen.io/seandaniel/pen/oNvKjop https://codepen.io/seandaniel/pen/oNvKjop

 .wrapper { width: 60rem; margin: 0 auto; }.section-1 { background-color: black; width: 100%; height: 200px; }.section-2 { background-color: blue; /* this width is just to show what I want it to look like */ width: 1224px; height: 200px; margin-left: auto; }.section-3 { background-color: orange; width: 100%; height: 200px; }
 <main> <div class="wrapper"> <section class="section-1"> </section> </div> <section class="section-2"> </section> <div class="wrapper"> <section class="section-3"> </section> </div> </main>
在此处输入图像描述

Is this what you want to happen?这是你想要发生的事情吗? The wrapper will stay the same distance from the left no matter what.无论如何,包装器将与左侧保持相同的距离。 Although I'm not sure if you want your wrapper in the center center (x,y) at all times.尽管我不确定您是否始终希望将包装器放在中心中心(x,y)。

CSS CSS

 .wrapper { border: 1px solid green; width: 100%; position: absolute; left: 45px; }.section-1 { background-color: black; width: 100%; height: 200px; position: relative; }.section-2 { background-color: blue; width: 125%; height: 200px; margin-left: auto; position: relative; }.section-3 { background-color: orange; width: 100%; height: 200px; position: relative; }
 <main> <div class="wrapper"> <section class="section-1"> </section> <section class="section-2"> </section> <section class="section-3"> </section> </div> </main>

  1. In your .section-2 class add the following css rule margin-right: calc(50% - 50vw);在您的.section-2 class 添加以下 css 规则margin-right: calc(50% - 50vw);
  2. You will also need to nest your <section class="section-2"></section> into the same <div class="wrapper"></div> as your other sections to have the same left alignment.您还需要将<section class="section-2"></section>嵌套到与其他部分相同的<div class="wrapper"></div>中,以获得相同的左侧 alignment。

If you want it to bleed to the left, use margin-left: calc(50% - 50vw);如果您希望它向左流血,请使用margin-left: calc(50% - 50vw); instead of margin-right , or have both to be full width.而不是margin-right ,或者两者都必须是全宽。

This page has a lot of good information about manipulating margins within a container.这个页面有很多关于在容器内操作边距的好信息。 Full Width Containers in Limited Width Parents有限宽度父级中的全宽容器

 .wrapper { width: 60rem; margin: 0 auto; }.section-1 { background-color: black; width: 100%; height: 200px; }.section-2 { background-color: blue; height: 200px; margin-right: calc(50% - 50vw); }.section-3 { background-color: orange; width: 100%; height: 200px; }
 <main> <div class="wrapper"> <section class="section-1"> </section> </div> <div class="wrapper"> <section class="section-2"> </section> </div> <div class="wrapper"> <section class="section-3"> </section> </div> </main>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM