html - 无法使子元素与父元素IE高度相同

标签 html css internet-explorer

我正在尝试使用 CSS 使表格单元格的子元素采用表格单元格的高度和宽度。这是 html:

<tr>
    <td>
        <div class="yellowDiv"></div>
    </td>
    <td></td>
    <td></td>
    <td></td>
</tr>

这是我正在使用的 CSS:



    table tbody tr td:nth-child(1){
        position: relative;
    }

    table tbody tr td div.yellowDiv{
        position: absolute;
        top: 0;
        bottom: 0;
        width: 100%;
        background: yellow;
    }

以上代码在 Chrome 中正确呈现,但在 IE 中不正确(仅与 IE 9 和 10 有关)。我还尝试为 div 元素设置 display: table-cell; 但无济于事。我还尝试将 div 元素的高度设置为 100%,但这也没有用。

最佳答案

绝对定位元素不再是布局的一部分。他们有自己的布局上下文。因此他们无法知道他们的父元素有多大。

您需要使用 JavaScript 来解决这个问题,或者考虑一下您为什么需要绝对定位。

您可以使用:

.yellowDiv {
    background-color:#ffff00;
    height:100%;
}

关于html - 无法使子元素与父元素IE高度相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19989430/

相关文章:

html - angular 5 : . scss 更改在 HTML 中未被识别

javascript - 在下一个 div 单击中更改 div 的背景颜色

jQuery 悬停效果 - 如何让它变慢

html - 设置 bootstrap 下拉宽度小于 240px

javascript - 脚本 16389 : Unspecified error -- Javascript code

html - 如何为您的网站添加 google chrome omnibox-search 支持?

html - HTML Canvas 的最大尺寸是多少?

html - 全屏显示 img 标签内的 SVG

javascript - Kendo UI 翻转效果在 Internet Explorer 中显示得太快

CSS - 按钮旁边的间距在 IE 中与在 Chrome 中不同。我该如何解决?