简体   繁体   English

桌子在绝对div内的高度为100%

[英]Table 100% height inside an absolute div

I have a table inside an absolute positioned div. 我在绝对定位的div中有一张桌子。 The div stretches using top 0 and bottom 0, and it seems it stretches as expected cross-browser. div使用顶部0和底部0延伸,并且看起来像预期的跨浏览器一样延伸。 (I checked, I put on a border on it and it stretched as expected). (我检查了一下,在上面加了边框,然后按预期的方向拉伸了)。 Now, inside the div I have a table. 现在,在div内有一张桌子。 I want the table to stretch on all of the div space, and in Google Chrome it does. 我希望表格能在所有div空间上伸展,而在Google Chrome中确实如此。 But in Internet Explorer and Firefox it is not, the table stretches to the width, but ignores the height property, and its height is determined by its contents. 但是在Internet Explorer和Firefox中却不是,表格会扩展到宽度,但会忽略height属性,并且其高度取决于其内容。

Is there a way to fix it, or bypass it somehow? 有没有办法解决它,或者以某种方式绕过它?

Here is the code: 这是代码:

<div
    style=
        "position:absolute;
         top:40px;
         left:0px;
         right:0px;
        bottom:0px;">
    <table
        width="100%"
        cellpadding="0"
        cellspacing="0"
        style="height:100%;">
    </table>
</div>

Define a height of your div , 定义divheight

<div style="position:absolute; top:40px; left:0px; right:0px; background-color: #f90; bottom:0px; height: 400px">
    <table width="100%" cellpadding="0" cellspacing="0" style="height:100%;">     
    </table>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM