Only if the parent element has a defined height, i..e not a value of auto
. If that has 100% height, the parent's parent height must be defined, too. This could go until to the html
root element.
So set the height of the html
and the body
element to 100%
, as well as every single ancestor element of that element that you wish to have the 100%
height
in the first place.
See this example, to make it clearer:
html, body, .outer, .inner, .content {
height: 100%;
padding: 10px;
margin: 0;
background-color: rgba(255,0,0,.1);
box-sizing: border-box;
}
<div class="outer">
<div class="inner">
<div class="content">
Content
</div>
</div>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…