This question already has answers here:
inherit from another class
(4个答案)
三年前关闭。
这是一个简单的问题,我只是不知道如何在网上搜索。
我有三个班级:CSS.header.cell。它们看起来如下:
.header
{
    display:table-cell;
    vertical-align:middle;
    width:130px;
    height:20px;
    background-color: Yellow;
    border: 1px solid silver;
}
.cell
{
    display:table-cell;
    vertical-align:middle;
    width:130px;
    height:85px;
    background-color: Yellow;
    border: 1px solid silver;
}
.footer
{
    display:table-cell;
    vertical-align:middle;
    width:130px;
    height:40px;
    background-color: Yellow;
    border: 1px solid silver;
}

所有这些类之间的唯一区别是.footer属性。如何简化此代码?
谢谢。

最佳答案

使用,分隔公共属性的选择器列表中的元素:

.foo, .bar {
   color: red;
}

.foo {
   font-size: 120%;
}

.bar {
   font-size: 80%;
}

这将使.foo.bar都变为红色,但文本大小不同。

10-01 07:07
查看更多