Html 在CSS中继承类
假设CSS中有两个类-Html 在CSS中继承类,html,css,inheritance,Html,Css,Inheritance,假设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
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>
index.html-
<div class="childDiv">I'm the Child</div>
我是孩子
但它会丢弃中断。您可以这样做:
.fatherDiv, .childDiv {
background-color: #b0c4de;
width: 350px;
height: 280px;
}
.childDiv
{
font-family: Arial,Helvetica,sans-serif;
font-size: 50px;
}
您也可以不调用这些元素child
和father
。他们是兄弟姐妹。您可以这样做:
.fatherDiv, .childDiv {
background-color: #b0c4de;
width: 350px;
height: 280px;
}
.childDiv
{
font-family: Arial,Helvetica,sans-serif;
font-size: 50px;
}
您也可以不调用这些元素child
和father
。他们是兄弟姐妹。请检查此项-
检查这个-
比如:
.fatherDiv {
background-color: #b0c4de;
width: 350px;
height: 280px;
}
.childDiv {
background-color:inherit;
width:100%;
height:100%;
font-family: Arial,Helvetica,sans-serif;
font-size: 50px;
}
理论上,只要您的HTML如下所示:
<div class="fatherDiv">
<div class="childDiv"></div>
</div>
虽然inherit
对所有CSS值都无效,所以您必须检查它
它不会自动继承值,您需要像Sass这样的预处理器才能做到这一点。类似于:
.fatherDiv {
background-color: #b0c4de;
width: 350px;
height: 280px;
}
.childDiv {
background-color:inherit;
width:100%;
height:100%;
font-family: Arial,Helvetica,sans-serif;
font-size: 50px;
}
理论上,只要您的HTML如下所示:
<div class="fatherDiv">
<div class="childDiv"></div>
</div>
虽然inherit
对所有CSS值都无效,所以您必须检查它
它不会自动继承值,您需要像Sass这样的预处理器才能做到这一点。您的查询不清楚。您的查询不清楚。