CSS表命名

时间:2010-07-07 03:38:05

标签: css html-table

有什么办法可以将这个CSS代码重命名为仅影响某个表而不是我网站上的所有表吗?

 th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
 }

 th.nobg {
border-top: 0;
border-left: 0;
background: #C1DAD7;
 }

 td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
 }

 td.alt {
background: #F5FAFA;
color: #797268;
 }

 th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 }

 th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
 }

和HTML代码:

 <table id="mytable" cellspacing="0"> 
   <tr> 
   <th width="202" class="nobg" scope="col">Configurations</th> 
   <th width="250"></th> 
 </tr> 
 <tr> 
   <th scope="row" class="spec">Model</th> 
   <td>M9454LL/A</td> 
 </tr> 
 <tr> 
   <th scope="row" class="specalt">G5 Processor</th> 
   <td class="alt">Dual 1.8GHz PowerPC G5</td> 
 </tr> 
 <tr> 
   <th scope="row" class="spec">Frontside bus</th> 
   <td>900MHz per processor</td> 
</tr> 
<tr> 
   <th scope="row" class="specalt">Level2 Cache</th> 
   <td class="alt">512K per processor</td> 
</tr> 
</table>

4 个答案:

答案 0 :(得分:2)

您可以更改CSS选择器以仅匹配特定的表ID,例如......

#mytable th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
 }

#mytable th.nobg {
border-top: 0;
border-left: 0;
background: #C1DAD7;
 }

#mytable td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
 }

答案 1 :(得分:1)

table#mytable放在每个css选择器前面。

table#mytable th{
}
table#mytable th.nobg{
}
table#mytable td{
}
table#mytable td.alt{
}
table#mytable th.spec{
}
table#mytable th.specalt{
}

或只是#mytable

#mytable th{
}
#mytable th.nobg{
}
#mytable td{
}
#mytable td.alt{
}
#mytable th.spec{
}
#mytable th.specalt{
}

答案 2 :(得分:1)

要专门定位显示html代码的表,请执行以下操作:

#mytable th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
 }

#mytable th.nobg {
border-top: 0;
border-left: 0;
background: #C1DAD7;
 }

#mytable  td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
 }

#mytable  td.alt {
background: #F5FAFA;
color: #797268;
 }

#mytable  th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 }

#mytable th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
 }

你不需要全表#mytable。

答案 3 :(得分:1)

您可以在每个规则前加上您的表ID(#mytable),这样您就可以使用

#mytable th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
 }

 #mytable th.nobg {
border-top: 0;
border-left: 0;
background: #C1DAD7;
 }

 #mytable td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
 }

 #mytable td.alt {
background: #F5FAFA;
color: #797268;
 }

 #mytable th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
 }

 #mytable th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
 }