以下是测试代码。
<!DOCTYPE html>
<html style="min-width:100%;min-height:100%;height:100%;width:100%">
<body style="margin:0;min-width:100%;min-height:100%;height:100%;width:100%">
<div style="display:table;width:100%;height:100%;min-wight:100%;min-height:100%;">
<div style="display:table-row;background:red;">A</div>
<div style="display:table-row;background:green;">
<div style="display:block;background:yellow;width:100%;height:100%;">B</div>
</div>
<div style="display:table-row;background:blue;height:50px;">C</div>
</div>
</body>
</html>
Firefox和Opera显示黄色div很小(类似于table-row但设置了display:block)。 Chrome则会在绿色div(table-row)的100%高度上显示黄色div。
我希望在Firefox,Opera和IE> 8中像在Chrome中一样正常工作!
更新:
我发现了以下问题:
<!DOCTYPE html>
<html style="min-width:100%;min-height:100%;height:100%;width:100%">
<body style="margin:0;min-width:100%;min-height:100%;height:100%;width:100%">
<div style="display:table;width:100%;height:100%;min-wight:100%;min-height:100%;">
<div style="height:50px;display:table-row;background:red;">A</div>
<div style="display:table-row;background:green;">
<div style="display:table-cell;background:yellow;">
<div style="display:block;width:100%;height:100%;background:darkred;">B</div>
</div>
</div>
<div style="display:table-row;background:blue;height:50px;">C</div>
</div>
</body>
</html>
在Opera中无法正常显示深红色的div!
display:table-cell
,因为CSS定义了单元格将根据需要自动生成。但这意味着,在其缺失时,display:block; height:100%
是生成单元格高度的100%。似乎浏览器在生成单元格的高度上存在差异。您的解决方案通过明确设置单元格的高度消除了这种歧义。 - Alohci