我想讓一個類完全流血,但我不能。內嵌塊CSS無法使元素全寬
下面是HTML:
<div class="main-class">
<div class="background">
<p>some info in the background</p>
</div>
<div class="content">
<p>Some random content</p>
</div>
</div>
和css:
.main-class{
padding: 20px;
width: 100%;
background-color: #fff;
display: inline-block;
box-sizing: border-box;
}
.background{
margin: -20px;
background-color: #eee;
display: inline-block; // must use inline-block
width: 100%;
padding: 20px;
box-sizing: border-box;
}
.content{
margin-top: 30px;
}
,這裏是一個演示:https://jsfiddle.net/uumkjLy8/1/
背景類必須是全出血與背景,但所看到的演示在右側有空白區域。
這是一個糟糕的解決方案,它會給OP一個水平滾動。 – coderodour