【发布时间】:2014-05-04 14:14:34
【问题描述】:
我有一篇 960 像素宽的博文。
我希望这篇博文的部分内容覆盖 100% 的视口(从左:0 到右:0)。使用绝对定位相当容易,但使用这种方法不可能清除这些 100% 宽的元素。
HTML:
<div class="wrapper">
<h1>A header</h1>
<p>Some content.</p>
<div class="out">
<blockquote>Some blockquote.<br/> Another line.<br/>And another.</blockquote>
</div>
<p>Clears don't work here and this content is invisible :( </p>
<p>And this sucks :( </p>
<div class="out">
<blockquote>And different blockquote.<br/> Another line.<br/></blockquote>
</div>
<p>Also this is behind blockquote as well.</p>
</div>
CSS:
body {
position: relative;
}
.wrapper {
margin: 0 auto;
padding: 15px;
background: #eee;
width: 400px;
height: 1000px;
}
.out {
position: absolute;
right: 0;
left: 0;
padding: 15px;
background: #aaa;
width: 100%:
}
blockquote {
margin: 0 auto;
width: 400px;
}
这是一个演示:
注意:所有块引用都有不同的高度,所以我不能为它们设置它。我不想使用 JavaScript(因为获取元素高度、设置 this 和繁荣相当容易,但谁用 JS 呈现内容?!)。
【问题讨论】:
-
你可以试试简单的 .out {background: #AAAAAA;边距:0 -15px; padding: 15px;} 你在找这样的东西吗jsfiddle.net/2rC2S/3
-
标签: css position width absolute clearfix