height:100%与height:inherit的区别

简介

  • 大部分情况下两者的表现都是一致的,但是兼容性不同 百分比 IE6+inherit IE8+
  • 但是在小部分情况下inherit,会表现的更加强大
  • 百分比是直接继承父元素的百分比,如果父元素没有高度,那么100%的子元素也是没有高度的

定位布局

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .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;
        }
    </style>
</head>

<body>
    <div class="outer">
        <div class="height-100">100%</div>
    </div>
    <div class="outer">
        <div class="height-inherit">inherit</div>
    </div>
</body>

结果
在这里插入图片描述

MDN

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值