CSS表命名

标签 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>

最佳答案

您可以更改 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;
 }

关于CSS表命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3191730/

相关文章:

css - 造型单选按钮

html - 视频标签填充 100% div,无论比例如何

html - MPDF 设置列 - 列高度

html - IE11 : very poor perfomance in rendering tables - any solutions?

html - 如何设置只有垂直单元格间距的表格样式?

html - 无法更改固定布局表中的列大小

javascript - 如何将表头的 h-scroll 与表体的 h-scroll 链接起来,而不将表体的 v-scroll 与表头链接起来?

wordpress 中的 html 转换表太宽,不适合全宽页面模板

html - 没有社交媒体元素的导航栏崩溃

html - 如何修复使用 CSS 渲染时图像模糊的问题?