一、兼容性
首先,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>