谁能解释一下 inherit
关键字在 CSS 中的含义及其工作原理?
最佳答案
它将使用与其父级具有的相同属性相同的值。
body {
margin: 234px;
}
h1 {
margin: inherit; /* this equals 234px in this instance */
}
<body>
<h1></h1>
</body>
如果 <h1>
有多个实例在文件中,它将占用其父元素的边距,因此 234px 并不总是它的值。例如:
<body>
<h2></h2>
<div>
<h2></h2>
</div>
</body>
body {
margin: 20px;
}
div {
margin: 30px;
}
h2 {
margin: inherit; /* 20px if parent is <body>; 30px if parent is <div> */
}
关于css - CSS中的inherit关键字有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2002514/