随着表格行的高度增加,我希望内部的 div 也能自动匹配它。
对于上面的代码,我的 div
的高度总是0
.
据我所知,height:inherit
仅当您明确声明父级 ( <td>
) 的高度时才有效,但我不想这样做,因为我不知道那里将显示什么内容高度。
是否有任何 css 技巧可以做到这一点,还是我必须求助于一些 JS?
最佳答案
你不能使用 height
规则,但你仍然可以通过绝对定位 div 来达到你想要的效果。由于这会更改 div 的布局,因此您必须将宽度应用于 td
:
td.fooed {position:relative; width:30px;}
td.fooed .foo {
position:absolute; top:0px; left:0px; right:0px; bottom:0px;
background:gray;
}
这是你的 fiddle :http://jsfiddle.net/ZAvDd/2/
关于html - 仅使用 css 使 <div> 继承父级 (<td>) 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14442747/