【发布时间】:2009-10-25 18:54:48
【问题描述】:
我有以下代码可以模仿我的问题。我想使用百分比为“容器”div 中的元素设置样式。因此,我必须将“容器”div 设置为高度 100%(或其他值)才能完成这项工作。当我希望“容器” div 更改高度以反映内容时,就会出现问题。在下面的情况下,我希望高度为 200%(在这种情况下,因为我知道“容器”的内容,但我在现实世界的情况下有一个具有不同行数的数据网格)。如果我将高度设置为自动,则无法使用百分比更改子元素。 有什么办法可以解决这个问题,还是我设置了固定高度的容器?
谢谢,
富有。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html style="height:100%">
<body style="height:100%">
<form style="height:100%">
<div id="Container" style="border:solid 5px;min-height:100%;height:100%">
<div style="height:100%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
<div style="height:10%; color:red"> TEST </div>
</div>
</form>
</body>
</html>
【问题讨论】: