【发布时间】:2011-08-23 12:01:32
【问题描述】:
这是我的 HTML 的一个小 sn-p:
<img src="http://hss.fullerton.edu/philosophy/Red%20Square.gif" id="test1" />
<table id="test2">
<tr><td>Test</td></tr>
</table>
我有一个红色正方形的图像,我希望表格与它的底部重叠。这是 CSS:
#test1 {
width: 42px;
height: 42px;
display: block;
margin-left: auto;
margin-right: auto;
margin-bottom: -15px;
}
#test2 {
z-index: 1;
background-color: pink;
width: 80px;
height: 50px;
margin-left: auto;
margin-right: auto;
}
但它不起作用:
如您所见,图像仍位于table 之上——这不是我想要的。请注意,在我的 CSS 中,我已将表格的 z-index 明确设置为 1,但它仍然不会与图像重叠。我做错了什么?
jsFiddle: http://jsfiddle.net/george_edison/uk7Pz/
【问题讨论】:
-
我认为 z-index 仅适用于定位元素。如果你给桌子
position:relative,它可能会起作用,但同样可能不会。 -
@sdleihssirhc 是对的。你应该把它作为一个答案,这样你就可以获得它的功劳。
-
是的,它适用于 AFAICT:jsfiddle.net/uk7Pz/1
-
我会把它作为一个答案,但我不知道它是否可以在 IE6 中工作(你可能需要
zoom:1或其他什么......谁知道),我不知道现在可以访问它。
标签: html css image html-table overlap