天天看點

css height 100% 無效

height 100% 無效

In order for a percentage value to work for height, the parent’s height must be determined. The only exception is the root element , which can be a percentage height. .

So, you’ve given all of your elements height, except

隻有父元素的高度設定了(不是百分比)的情況下,子元素的height 百分比的值才能生效,除了 root 元素(html, body)

html {
    height: 100%;
}
           

或者

* { padding: 0; margin: 0; }
html, body, #fullheight {
    min-height: 100% !important;
    height: 100%;
}
#fullheight {
    width: 250px;
    background: blue;
}
           
<div id=fullheight>
  Lorem Ipsum        
</div>