表内有不同风格的表?

时间:2013-03-01 08:46:25

标签: css html-table

如何为两个表格单元格制作两种不同的样式,其中一个单元格位于另一个表格内?

我有两种css样式:

table.style1 { /* any styles */}
table.style1 td { /* any styles */}

table.style2 { /* any styles */}
table.style2 td { /* any styles */ }

在代码中,我有这样的情绪:

<table class="style1">
   <tr>
      <td>
         <table class="style2">
            <tr><td>bla bla<td></tr>
         </table>
      </td>
   <tr>
</table>

结果是 - 第二个表(带有style2)中的所有<td>个表格单元格都是style1 ...!

当桌子里面有桌子时,如何制作两个不同的css窗框?

3 个答案:

答案 0 :(得分:5)

试试这段代码。我相信它运作正常。

table.style1 { /* any styles */}

table.style1 td { /* any styles */}

table.style1 table.style2 { /* any styles */}

table.style1 table.style2 td { /* any styles */}

答案 1 :(得分:3)

以下是选择不同表格单元格http://jsfiddle.net/HR8Bg/2/

的一种方法
.style1 td {
    background: blue;
    color: #fff;
}

.style1 td td {
    background: red;
}

答案 2 :(得分:-2)

您可以按照以下代码

表1

  

table .style1 {/ * any styles * /}

     

table .style1 td {/ * any styles * /}

表2

  

table .style1 .style2 {/ * any styles * /}

     

table .style1 .style2 td {/ * any styles * /}