简介
- 大部分情况下两者的表现都是一致的,但是兼容性不同
百分比 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>
结果