css高度差:100%vs height:auto [英] difference between css height : 100% vs height : auto

查看:216
本文介绍了css高度差: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆