• 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>
  • 相关阅读:
    rzc generate exited with code -2147450730.
    c#WebService动态调用
    c#BarTender打印,打印微调
    记一次ios下h5页面图片显示问题
    FID
    RSA密钥对生成,并解析公钥指数和模数
    angularjs-6
    angularjs-5
    angularjs-4
    angularjs-4
  • 原文地址:https://www.cnblogs.com/yuxinpeng/p/6196898.html
Copyright © 2020-2023  润新知