css高度差:100%vs height:auto [英] difference between css height : 100% vs height : auto
问题描述
我在一个采访中问了一个问题:css height:100%
和 height:auto之间的区别是什么c $ c>?
任何人都可以解释?
height:100%
表示元素的父容器的高度为100%。
height :auto
表示元素将具有灵活的高度,即其高度将取决于其子元素的高度。
请考虑以下示例: / p>
height:100%
; div style =height:50px>
< div id =innerDivstyle =height:100%>
< / div>
< / div>
#innerDiv
c $ c> height:50px
height:auto
$ b b
< div style =height:50px>
< div id =innerDivstyle =height:auto>
< div id =evenInnerstyle =height:10px>
< / div>
< / div>
< / div>
现在 #innerDiv
height:10px
I was asked a question in an interview that "what is the difference between the css height:100%
and height:auto
?"
Can any one explain?
height:100%
implies the element is going to have the 100% height of its parent container.
height:auto
means, the element will have flexible height i.e. its height will depend upon the height of children elements of it
Consider below example:
height:100%
<div style="height:50px">
<div id="innerDiv" style="height:100%">
</div>
</div>
#innerDiv
is going to have height:50px
height:auto
<div style="height:50px">
<div id="innerDiv" style="height:auto">
<div id="evenInner" style="height:10px">
</div>
</div>
</div>
now the #innerDiv
is going to have height:10px
这篇关于css高度差:100%vs height:auto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!