【发布时间】:2014-05-28 13:09:18
【问题描述】:
我在分层 div 时遇到了一些困难。我已经创建了问题区域的样本。
通过查看它,您可以看到背景图像 - 顶部是两个蓝色框和略微透明的黑色框。我要求该框位于两个框的后面,但位于背景图像的顶部。
现在我确实尝试为所有元素分配 z-index,但它没有改变任何东西?
<div class="hero">
<div class="container">
<div class="section group">
<div class="col span_2_of_4">
"headline here"
</div>
</div>
<div class="section group">
<div class="col span_1_of_4">
sub head
</div>
</div>
</div>
<div class="headerband"></div>
</div>
.hero{
position:relative;
height:60%;
background-image:url(http://asia.olympus-imaging.com/products/dslr/e520/sample/images/sample_03.jpg);
background-size:cover;
float: left;
width: 100%;
}
.headerband{
background-color: rgba(0,0,0,0.7);
height: 20%;
margin-top: -30px;
float:left;
z-index: -1;
width: 100%;
}
/* Main Container */
.container{
margin: 0 auto;
width: 960px;
padding: 20px 0 0 0;
}
/* Respinsive grid */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after {
content:"";
display:table;
}
.group:after {
clear:both;
}
.group {
zoom:1; /* For IE 6/7 */
}
/* Grid of four */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 74.6%;
background-color: blue;
}
.span_2_of_4 {
width: 49.2%;
background-color: #008394;
color: #FFF;
padding: 30px 20px 30px 20px;
font-size: 30px;
text-align:center;
margin-bottom: -10px;
margin-top: 370px;
}
.span_1_of_4 {
width: 28.8%;
background-color: #00C1DB;
color: #FFF;
padding: 20px 20px 20px 20px;
font-size: 15px;
text-align:center;
}
【问题讨论】: