【发布时间】:2014-05-07 21:14:30
【问题描述】:
假设在 CSS 中有两个类 - fatherDiv 和 childDiv -
.fatherDiv {
/*
With background and no special font color
*/
background-color: #b0c4de;
width: 350px;
height: 280px;
}
.childDiv {
font-family: Arial,Helvetica,sans-serif;
font-size: 50px;
}
并希望.childDiv 继承所有.fatherDiv 样式并添加更多。
常见的做法是这样做——
<div class="fatherDiv childDiv">I'm the Child</div>
但我的问题是——
是否可以选择将类样式继承到 CSS 文件中的另一个类?
我试过了——
style.css -
.fatherDiv .childDiv {
/*
Inherit from .fatherDiv ...
*/
font-family: Arial,Helvetica,sans-serif;
font-size: 50px;
}
index.html -
<div class="childDiv">I'm the Child</div>
但它丢弃了干扰。
【问题讨论】:
-
您的查询不清楚。
标签: html css inheritance