避免复制CSS样式?

避免复制CSS样式?,css,Css,我正在使用Html和JQuery。我的styles.CSS中有以下CSS样式 #someTable{ -moz-border-radius: 15px; border-radius: 15px; border:1px solid; width:80%; height:98px; padding-top: 20px; padding-bottom: 20px; padding-left: 20px; background-co

我正在使用Html和JQuery。我的styles.CSS中有以下CSS样式

#someTable{
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:1px solid;
    width:80%;
    height:98px;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    background-color:mintcream;
}


在上述css样式中,除了背景色之外,所有样式都是相同的,其余所有样式都是重复的。如何避免重复并扩展
firstTable
的属性?

您可以使用类。它看起来是这样的:

CSS:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>
html:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>

您可以使用类。它看起来是这样的:

CSS:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>
html:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>

您可以使用类。它看起来是这样的:

CSS:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>
html:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>

您可以使用类。它看起来是这样的:

CSS:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>
html:

.masterclass{ here you put all the properties that are the same } 

#table1 { here the specific details , your color in this case }
#table2 { here the specific details , your color in this case }
<table class='masterclass' id='table1'> </table>
<table class='masterclass' id='table2'> </table>

您可以将它们组合在一起,并重新定义异常:

#someTable, #anotherTable{
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:1px solid;
    width:80%;
    height:98px;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    background-color:mintcream;
}

#anotherTable{
    background-color:white; /* Set the exception */
}
我假设您不能设置
表格的样式。您可以从组中删除背景色,并将其设置为自己的组,如
#另一个表
,但这将为您节省4行:)


您可以为两个表都提供一个类,并将其用作“组”选择器,但ID的速度要比类快得多。在这种情况下,IMO,您应该坚持使用ID。

您可以将它们组合在一起,并重新定义异常:

#someTable, #anotherTable{
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:1px solid;
    width:80%;
    height:98px;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    background-color:mintcream;
}

#anotherTable{
    background-color:white; /* Set the exception */
}
我假设您不能设置
表格的样式。您可以从组中删除背景色,并将其设置为自己的组,如
#另一个表
,但这将为您节省4行:)


您可以为两个表都提供一个类,并将其用作“组”选择器,但ID的速度要比类快得多。在这种情况下,IMO,您应该坚持使用ID。

您可以将它们组合在一起,并重新定义异常:

#someTable, #anotherTable{
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:1px solid;
    width:80%;
    height:98px;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    background-color:mintcream;
}

#anotherTable{
    background-color:white; /* Set the exception */
}
我假设您不能设置
表格的样式。您可以从组中删除背景色,并将其设置为自己的组,如
#另一个表
,但这将为您节省4行:)


您可以为两个表都提供一个类,并将其用作“组”选择器,但ID的速度要比类快得多。在这种情况下,IMO,您应该坚持使用ID。

您可以将它们组合在一起,并重新定义异常:

#someTable, #anotherTable{
    -moz-border-radius: 15px;
    border-radius: 15px;
    border:1px solid;
    width:80%;
    height:98px;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    background-color:mintcream;
}

#anotherTable{
    background-color:white; /* Set the exception */
}
我假设您不能设置
表格的样式。您可以从组中删除背景色,并将其设置为自己的组,如
#另一个表
,但这将为您节省4行:)


您可以为两个表都提供一个类,并将其用作“组”选择器,但ID的速度要比类快得多。在这种情况下,IMO,您应该坚持ID。

我肯定会使用类来实现您想要的。以下用途:

然后在HTML中:

<table class="Table">...</table>

<table class="Table Table--primary">...</table>

<table class="Table Table--secondary">...</table>
。。。
...
...

我肯定会使用类来实现您想要的功能。以下用途:

然后在HTML中:

<table class="Table">...</table>

<table class="Table Table--primary">...</table>

<table class="Table Table--secondary">...</table>
。。。
...
...

我肯定会使用类来实现您想要的功能。以下用途:

然后在HTML中:

<table class="Table">...</table>

<table class="Table Table--primary">...</table>

<table class="Table Table--secondary">...</table>
。。。
...
...

我肯定会使用类来实现您想要的功能。以下用途:

然后在HTML中:

<table class="Table">...</table>

<table class="Table Table--primary">...</table>

<table class="Table Table--secondary">...</table>
。。。
...
...


将所有公共属性组合成一个
,然后为
背景色
覆盖创建另外两个类。将所有公共属性组合成一个
,然后为
背景色
覆盖创建另外两个类。将所有公共属性组合成一个
,然后为
背景色
覆盖创建另外两个类。将所有公共属性组合成一个
,然后为
背景色
覆盖创建另外两个类。当然,您也可以堆叠类,或者在此处执行#table1,#table2{这两个id相同}。但在我看来,使用课堂是最好的做法。我不同意这一点。Id总是比类快,因此最好(在本例中,IMO)坚持使用Id。你说得对,Id的速度更快,因此+1。基于类的方法更可重用,并实现CSS的真正功能,即级联。创建一个属性始终相同的基类,然后使用修饰符类或ID来修改和扩展(例如背景颜色)。当然,您也可以堆叠类,或者执行#table1,#table2{这里的东西使两个ID相同}。但在我看来,使用课堂是最好的做法。我不同意这一点。Id总是比类快,因此最好(在本例中,IMO)坚持使用Id。你说得对,Id的速度更快,因此+1。基于类的方法更可重用,并实现CSS的真正功能,即级联。创建一个属性始终相同的基类,然后使用修饰符类或ID来修改和扩展(例如背景颜色)。当然,您也可以堆叠类,或者执行#table1,#table2{这里的东西使两个ID相同}。但在我看来,使用课堂是最好的做法。我不同意这一点。Id总是比类快,因此最好(在本例中,IMO)坚持使用Id。你说得对,Id的速度更快,因此+1。基于类的方法更可重用,并实现CSS的真正功能,即级联。创建一个属性始终相同的基类,然后使用修饰符类或ID来修改和扩展(例如背景颜色)。当然,您也可以堆叠类,或者执行#table1,#table2{这里的东西使两个ID相同}。但在我看来,使用课堂是最好的做法。我不同意这一点。Id总是比类快,因此最好(在本例中,IMO)坚持使用Id。你说得对,Id的速度更快,因此+1。基于类的方法更可重用,并实现CSS的真正功能,即级联。创建一个基类