我试图建立与下面的图片示意地呈现CSS样式的HTML的中心位置: alt text http://www.freeimagehosting.net/uploads/216e5750a8.png动态DIV框的高度与孩子DIV
我设法内格与下面的HTML的位置:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<body>
<div style="background-color: yellow; width: 100px; height: 100px;
position: relative;">
<div style="background-color: gray; position: absolute;
top: 8px; left: 8px; right: 8px; bottom: 8px"></div>
</div>
</body>
</html>
但问题是,它停止工作,如果我想外部div的高度是动态的。删除高度值隐藏外部div。
在所有条件下如何实现?
你究竟在做什么?无论外部DIV的高度如何,垂直居中内部DIV? – 2009-07-02 11:19:23
外部div内没有内容,它会自行崩溃。内部div中是否有任何内容? – peirix 2009-07-02 11:27:21