我有以下情况:
我无法得到最后一点。如果不清楚,那么希望this demo应该有所帮助:我将叠加层与容器的顶部/底部对齐。相反,我希望它们与图像对齐。任何帮助表示赞赏!
答案 0 :(得分:2)
position: relative
不适用于表格单元格。
来自规范:http://www.w3.org/TR/CSS21/visuren.html#propdef-position
'position:relative'对table-row-group的影响, table-header-group,table-footer-group,table-row,table-column-group, table-column,table-cell和table-caption元素未定义。
因此,添加一个包装器div
并将position: relative
应用于该代码:
<div id="container">
<div> <!-- the wrapper -->
<img id="img" src="http://lh5.ggpht.com/-J7Q7cUDEFOU/S_bKEoyMSzI/AAAAAAAAGIw/PZJduitsVa0/largeNewGoogleLogoFinalFlat-a.png" />
<div class="overlay" id="top">Overlay top</div>
<div class="overlay" id="bottom">Overlay bottom</div>
</div>
</div>
#container > div {
position: relative;
}
答案 1 :(得分:0)
我认为您应该将图片放在<DIV>
中并在其中设置style="background:url()"
。然后在DIV
中,放置您想要定位的DIV
。它应该更容易。