我正在尝试构建图像网格。元素相对定位,因此浮动:left 似乎没有堆叠它们。有一个更好的方法吗?继承人的代码:
CSS:
#master {
width: 940px;
outline: solid 1px #000;
}
#img_grid1 h2 {
font-family: Tahoma, Geneva, sans-serif;
position: relative;
font-size: 16px;
top: 50px;
left: 20px;
color: #000;
z-index: 20;
width: 100px;
}
img.off {
position: absolute;
left: 0;
top: 0;
z-index: 10;
}
img.on {
position: absolute;
left:0; top: 0;
}
ul#img_grid1 { position: relative; }
ul#img_grid1 li {
position: relative;
list-style-type: none;
}
.copy {
position: relative;
width: 200px;
top: 70px;
left: 40px;
}
.copy p { color: #FFF; }
/* slightly enhanced, universal clearfix hack */
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-block; }
/* start commented backslash hack \*/
* html .clearfix { height: 1%; }
.clearfix { display: block; }
/* close commented backslash hack */
HTML:
<div id="master">
<br />
<ul id="img_grid1">
<li><a href="#" style="text-decoration: none;"><img class="off" src="images/img1.jpg" alt=""/><img class="on" src="images/img1over.jpg" alt=""/><h2>Heading 1</h2><div class="copy"><p>Love walking? Check out our fantastic range of quality walking gear. Plus... find out more about our FREE boot fitting service or check our brand new gear guide.</p></div>
</a></li>
<li><a href="#" style="text-decoration: none;"><img class="off" src="images/img1.jpg" alt=""/><img class="on" src="images/img1over.jpg" alt=""/><h2>Heading 1</h2><div class="copy"><p>Love walking? Check out our fantastic range of quality walking gear. Plus... find out more about our FREE boot fitting service or check our brand new gear guide.</p></div>
</a></li>
</ul>
不确定它是否可能。我试过浮动元素,但没有奏效。