zoukankan      html  css  js  c++  java
  • height:100%与height:inherit的区别

    一、兼容性

    首先,inherit这个属性只是在ie8+才支持;100%支持ie6;

    二、大多数情况下没有区别

    在正常情况下height:100%与height:inherit没有任何区别;

    1.父元素:height:auto;height:100%与inherit也都是auto;

    2.父元素定高:height:100px; height:100%与inherit也都是100px;

    三、绝对定位情况下大不同

    如果子元素为绝对定位元素,则height:100%;参考的父级是离它最近的有定位属性的父级而非直接父级;

    但是此时height:inherit;参考的依旧是直接父级,无论直接父级是否有定位属性;

    参考demo;

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style type="text/css">
            .wrap{
                width: 300px;
                height: 300px;
                border:5px solid red;
            }
            .box{
                width: 200px;
                height: 200px;
                border:5px solid yellow;
            }
            .child{
                width: 100px;
                height: 100px;
                border:5px solid blue;
            }
            .margin{
                top:50px;
                left:50px;
            }
            .abs{
                position:absolute;
            }
            .rel{
                position: relative;
            }
        </style>
    </head>
    <body>
        <div class="wrap">
            <div class="box">
                <div class="child abs"></div>
            </div>
        </div>
    </body>
    </html>
  • 相关阅读:
    oracle连接数
    python——包
    python——软件开发目录规范
    python——模块介绍
    python——二分法
    python——函数的递归调用
    python08——for 循环
    while循环嵌套练习题
    python07——while循环
    python06入门——流程控制之if判断
  • 原文地址:https://www.cnblogs.com/yuxinpeng/p/6196898.html
Copyright © 2011-2022 走看看