【发布时间】:2017-12-09 05:13:48
【问题描述】:
我需要让子 div 泄漏父容器的最大宽度。 现在,我只能泄漏父填充(知道)。
我需要这个来将所有页面包装在一个容器上并使某些部分泄漏。
没有这个,我需要在每个部分设置容器。
这里有一些sn-ps
.container {
max-width: 500px;
margin: 0 auto;
padding: 0 30px;
background: lightblue;
}
.child {
background: lightcoral;
height: 200px;
}
.child.cancel-padding {
margin: 0 -30px;
}
.child.leaked {
}
html,
body {
margin: 0;
padding: 0;
}
* {
text-align: center;
font-family: sans-serif;
}
<small>note: see in fullscreen or on codepen</small>
<h1>what i have</h1>
<div class="container">
<div class="child">A element inside a container</div>
</div>
<h1>what i need</h1>
<div class="container-leaked">
<div class="child leaked">
a element inside the container, but leaking all view width (100vw)
</div>
</div>
<h1>what i can do now</h1>
<div class="container">
<div class="child cancel-padding">Make the element cancel the parent padding, that's all</div>
</div>
<h1>Why i need</h1>
<p>
i will wrap all the page in the container, but sometimes i need sections to leak the container with full view width.
</p>
注意:在演示中,我设置了孩子的高度,但我无法控制它。这是一个动态内容 div,所以高度是动态的。
【问题讨论】: