0

我的所有表格元素( , 等...)都有 CSS 项目,<table><tr>我有一个表格,我不想应用 CSS。

让这个表格显示为原始 HTML 表格而不应用我的 CSS 格式的最快方法是什么。

另外,在我的 CSS 文件中,我有这个:

 table td 
 {
   padding: 5px;   
   border: solid 1px #e8eef4;
 }

 table th
 {
   padding: 6px 5px;
   text-align: left;
   background-color: #FFFFFF; 
   border: solid 1px #e8eef4;   
 }

如果我想拥有多种表格格式,我该怎么做?

4

2 回答 2

3

您应该使用类来定义几种不同的样式,例如:

// 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/

于 2009-07-21T11:15:42.600 回答
0

为要格式化的表使用一个类。例如

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

现在在 css 方面确保定义正确的格式,如下所示:

table.myformat th {
    color: red;
}

table.myformat td {
    color: green;
}

具有该class="myformat"属性的表将具有格式。那些不会的。使用这种方法,您可以进一步将各种表格格式制作为不同的类,并将它们应用于您的不同表格。

于 2009-07-21T11:15:10.837 回答