我可以在 CSS 中创建“类继承”吗?像这样的东西:
.squareButton {width:20px; height:20px; margin:1px solid;}
.squareRedButton {.squareButton; background:red;}
最佳答案
是的,你可以,只需将所需的 CSS 应用于你需要的两个类:
.squareButton, .squareRedButton {
width : 20px;
height : 20px;
margin : 1px solid;
}
.squareRedButton {
background : red;
}
注意
您可以通过 HTML 来使用多个类来执行继承,如下所示:
CSS
.squareButton {
width : 20px;
height : 20px;
margin : 1px solid;
}
.squareRedButton {
background:red;
}
HTML
<button class="squareButton squareRedButton">MyButton</button>
关于CSS类继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33756465/