转载CSS中height:100%和height:inherit的异同
2016-08-18 17:49
531 查看
说明:原文链接 http://www.zhangxinxu.com/wordpress/2015/02/different-height-100-height-inherit/comment-page-1/
原文总览:
1. 兼容性差异
2. 大多数情况作用是一样的
除去兼容性,大多数情况下,两者作用是一样的,甚至都很难想出不一样的理由。
① 父容器
② 父容器定高
难道没有差异吗?难道没有使用
3. 绝对定位大不同
当子元素为绝对定位元素,同时,父容器的
CSS代码:
HTML代码:
结果:
4. 总结
总之,这里,
大神的网站: http://www.zhangxinxu.com/wordpress/
HTML代码:
原文总览:
height:100%和height:inherit的异同
1. 兼容性差异height:100%IE6+ √
height:inheritIE8+ √
2. 大多数情况作用是一样的
除去兼容性,大多数情况下,两者作用是一样的,甚至都很难想出不一样的理由。
① 父容器
height: auto,无论
height:100%或者
height:inherit表现都是
auto.
② 父容器定高
height: 100px,无论
height:100%或者
height:inherit表现都是
100px高.
难道没有差异吗?难道没有使用
height:inherit的理由吗?当然有,记住,江湖上所发生的一切事情,都绝非偶然!
3. 绝对定位大不同
当子元素为绝对定位元素,同时,父容器的
position值为
static的时候,呵呵呵,
height:100%和
height:inherit的差异就可以明显体现出来了!
CSS代码:
<pre name="code" class="css">.outer { display: inline-block; height: 200px; width: 40%; border: 5px solid #cd0000; } .height-100 { position: absolute; height: 100%; width: 200px; background-color: #beceeb; } .height-inherit { position: absolute; height: inherit; width: 200px; background-color: #beceeb; }
HTML代码:
<pre name="code" class="DlHighlight html" style="font-stretch: normal; font-size: 14px; line-height: 1.3; font-family: Consolas, Monaco, monospace; padding: 5px 10px; margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; word-wrap: break-word; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255);"><pre name="code" class="DlHighlight html" style="margin-top: 0px; margin-bottom: 0px; color: rgb(51, 51, 51); font-size: 14px; line-height: 1.3; font-stretch: normal; font-family: Consolas, Monaco, monospace; padding: 5px 10px; white-space: pre-wrap; word-wrap: break-word; background-color: rgb(255, 255, 255);"><span class="paren xml-tagangle" style="color: rgb(0, 0, 153);"></span><pre name="code" class="html"><div class="outer"><div class="height-100"></div></div> <div class="outer"><div class="height-inherit"></div></div>
结果:
<img src="https://img-blog.csdn.net/20160818180124141?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
4. 总结
总之,这里,
height:inherit的强大好用可见一斑。回头,容器高度变化了,里面的绝对定位元素依然高度自适应。这是很赞的特性,因为如果页面很复杂,避免使用
position: relative会让你少去很多
z-index混乱层级覆盖的麻烦。
大神的网站: http://www.zhangxinxu.com/wordpress/
HTML代码:
相关文章推荐
- CSS中height:100%和height:inherit的异同
- CSS中height:100%和height:inherit的异同
- CSS中height:100%和height:inherit的异同
- CSS中height:100%和height:inherit的异同
- css 中 height:100% 和 height:inherit 异同
- 深入理解CSS的height:100%和height:inherit之间的使用区别
- height:100%和height:inherit的区别【转】
- CSS的inherit与auto
- 【css】容器撑满浏览器--- height:100%
- CSS的inherit与auto使用分析
- CSS的inherit与auto使用分析
- IE6 CSS高度height:100% 无效解决方法总结
- 纯CSS 实现DIV 高度 height 100% 全屏布局
- css中height:100%不起作用的解决方法
- css中height:100%不起作用的解决方法
- CSS中设置height:100%无效的解决方案
- CSS中min-height:100%问题
- CSS的inherit与auto
- CSS的inherit与auto使用分析
- css中height:100%不起作用的解决方法