绝对定位在IE中的表单元格内

问题描述:

我在Internet Explorer中的表格单元格中有一些绝对定位的问题(9具体,但我确定问题存在于< 9)。我试图强迫一个表格单元格内的div占据整个单元格。这在chrome / ff / safari使用很容易:

I'm having some issues with absolute positioning inside a table cell in Internet Explorer (9 specifically, but I'm sure the issue exists in <9 as well). I'm trying to force a div inside a table cell to take up the whole cell. It was pretty easy in chrome/ff/safari using:

div {
    position: absolute;
    top:0;
    bottom:0;
    right:0;
    left:0;
}

td {
    position: relative;
}

但是由于某种原因,IE的行为完全不同。我不能得到它给予div基于表单元格的动态高度。 这里是一个例子来显示我在说什么。它的工作原理我如何需要它在chrome / ff / safari,但它在IE中打破。有什么办法让它在IE中以相同的方式工作吗?谢谢!

But for some reason, IE behaves completely differently. I can't get it to give the div a dynamic height based on the table cell at all. Here's an example to show what I'm talking about. It works how I need it to in chrome/ff/safari, but it's broken in IE. Is there any way to get it to work the same way in IE? Thanks!

我建议您不要将元素定位到所有方向,只使用其中两个,您的div。

I recommend you instead of positioning your element to all directions, use only two of them and instead, use size for your div.

like:

div {
    position: absolute;
    top:0;
    bottom:0;
    width: 100%;
    height: 100%
}

td {
    position: relative;
    width: 400px;
    height: 400px;
}