首页 > 为什么浮动元素无法设置height:100%

为什么浮动元素无法设置height:100%

只能通过padding-bottom大数值和margin-bottom负大数值来100%


参考https://developer.mozilla.org/en-US/docs/Web/CSS/max-height

The percentage is calculated with respect to the height of the containing block. If the height of the containing block is not specified explicitly, the percentage value is treated as none.

于是,当元素依赖于父元素时,这样做或许可以解决问题:

html, body {
    height:100%;
}

而对于脱离了布局的元素,比如position:absolute,就不需要指定父元素的高度了。


因为浮动元素已经脱离了布局,所以就没办法设置相对于父元素的高度。

【热门文章】
【热门文章】