使div的高度与TD相等(IE问题)

3

给定以下html示例,如何使绝对定位的div高度等于表格单元格的高度。这仅是IE浏览器的问题。

注意:该div不能影响单元格内容,因此采用绝对定位,并且行样式必须定义高度。

<html>
<table>
<tr style="height:100px;">
<td style="position:relative;width:200px;background-color:green;border:solid 2px green;">
    <div style="position:absolute;background-color:red;width:100%;height:100%;top:0px;left:0px;"></div>
    xyz
</td>
</tr>
</table>
</html>
1个回答

2

我通过在div和td的父元素上应用“height: inherit”来解决了这个问题。

<html>
<table>
<tr style="height:100px;">
<td style="position:relative;width:200px;height:inherit;background-color:green;border:solid 2px green;">
    <div style="position:absolute;background-color:red;width:100%;height:inherit;top:0px;left:0px;"></div>
    xyz
</td>
</tr>
</table>
</html>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接