2011-04-09 71 views

回答

1

如果图像的尺寸是固定的(比如,宽度200高度300),那么这样的事情应该工作:

HTML:

<div id="table-and-image-container"> 
    <table id="the-table">...</table> 
    <img src="..." id="the-image" /> 
</div> 

CSS:

#table-and-image-container 
{ 
    position: relative; 
    display: inline-block; 
} 
#the-table 
{ 
    z-index: 1; 
} 
#the-image 
{ 
    left: 50%; 
    margin-left: -100px; /* = 200px width of image/2 */ 
    margin-top: -150px; /* = 300px height of image/2 */ 
    position: absolute; 
    top: 50%; 
    z-index: 2; 
} 

包含#table-and-image-container将是表格的大小,因为position: absolute将采用#the-image超出尺寸算法和display: inline-block w生病将宽度减少到表的宽度而不是100%的容器。然后,您使用标准top/left/margin技巧将图像放置在中心位置,并使用z-index确保它位于顶部。

+0

谢谢Domenic,但这没有奏效。图像出现在表格的垂直中心,但在页面的水平中心(不是表格)上。看看这里:http://jsfiddle.net/wxuwt/任何想法如何解决? – PleaseHelpMe 2011-04-09 11:28:18

+0

@NeedExpertHelp:对于'#table-and-image-container',添加'float:left'或'display:inline-block'。 – thirtydot 2011-04-09 13:00:37

+0

@NeedExpertHelp:确实,'display:inline-block'是要走的路;编辑我的答案以反映这一点。 http://jsfiddle.net/wxuwt/4/ – Domenic 2011-04-09 22:12:30