您应该使用类来定义几种不同的样式,例如:
// global table styles - will be applied to all tables
table td
{
background-color: green;
}
// styles for tables with class "style1"
table.style1 td
{
border: solid 1px red;
}
table.style1 th
{
...
}
// styles for tables with class "style2"
table.style2 td
{
border: solid 1px blue;
background-color: white;
}
然后在要应用该样式的表上设置类属性:
<table class="style1"><tr><td> red border, green background </td></tr></table>
<table class="style2"><tr><td> blue border, white background </td></tr></table>
<table><tr><td> default border, green background </table>
这里 style1 应用于第一个表的 TD,style2 应用于第二个表的 TD。
请注意,全局样式(没有任何类名)适用于所有匹配元素(例如 TD),但这些样式可以被特定样式覆盖(如背景颜色所示,全局设置为绿色,但样式 2 被覆盖) .
顺便说一句:有关 CSS 的教程,请查看http://w3schools.com/css/。