cssheight

时间:2025-12-19 06:33:17编辑:莆田seo君

CSS中height:100%和height:inherit的异同 00 张鑫旭

height:100% 是设置的是百分比的高度height:inherit 是集成父级标签的高度主要的差异有下面几点:兼容性差异height:100% IE6+ √height:inherit IE8+ √大多数情况作用是一样的除去兼容性,大多数情况下,两者作用是一样的,甚至都很难想出不一样的理由。① 父容器height: auto,无论height:100%或者height:inherit表现都是auto.② 父容器定高height: 100px,无论height:100%或者height:inherit表现都是100px高.难道没有差异吗?难道没有使用height:inherit的理由吗?当然有,记住,江湖上所发生的一切事情,都绝非偶然!绝对定位大不同当子元素为绝对定位元素,同时,父容器的position值为static的时候,呵呵呵,height:100%和height:inherit的差异就可以明显体现出来了!这个时候inherit刚好是父级的高度而100%的时候高度则是超过了父级的高度,是最高的高度最后: height:inherit的强大好用可见一斑。回头,容器高度变化了,里面的绝对定位元素依然高度自适应。这是很赞的特性,因为如果页面很复杂,避免使用position: relative会让你少去很多z-index混乱层级覆盖的麻烦。

CSS中height:100%和height:inherit的异同 00 张鑫旭

b修改补充:继承的话,如果父元素是height:50%,那么子类使用继承只会是父类的50%.outer {display: inline-block;height: 50%; width: 40%;border: 5px solid #cd0000;}.height-100 {height: 100%; width: 200px;background-color: #beceeb;}.height-inherit {height: inherit; width: 200px;background-color: #beceeb;}兼容性差异height:100% IE6+ √height:inherit IE8+ √2. 大多数情况作用是一样的除去兼容性,大多数情况下,两者作用是一样的,甚至都很难想出不一样的理由。① 父容器height: auto,无论height:100%或者height:inherit表现都是auto.② 父容器定高height: 100px,无论height:100%或者height:inherit表现都是100px高.难道没有差异吗?难道没有使用height:inherit的理由吗?当然有,记住,江湖上所发生的一切事情,都绝非偶然!3. 绝对定位大不同当子元素为绝对定位元素,同时,父容器的position值为static的时候,呵呵呵,height:100%和height:inherit的差异就可以明显体现出来了!.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;}

上一篇:昆山中创软件

下一篇:没有了