【发布时间】:2014-04-09 08:34:00
【问题描述】:
我有一个相当简单的 CSS 问题。
我想创建一个遵循特定格式的表格。我想在同一页面上以不同的方式格式化多个表格。
我有这个:
CSS:
table.firstTable
{
border: 1px solid black;
}
td.firstTable
{
border: 1px solid black;
}
th.firstTable
{
border: 1px solid black;
background: #00003f;
font-color: #cfffff;
}
table.secondTable
{
border: 1px solid red;
}
td.secondTable
{
border: 1px solid red;
font-family: sans-serif;
}
th.secondTable
{
border: 1px solid red;
background: #cfffff;
font-color: #00003f;
}
我可以这样创建表的唯一方法是:
HTML:
<table class="firstTable">
<tr>
<th class="firstTable">Item</th>
<th class="firstTable">Quantity</th>
<th class="firstTable">Price</th>
</tr>
<tr>
<td class="firstTable">0-001</td>
<td class="firstTable">Computer</td>
<td class="firstTable">$299.99</td>
</tr>
...
</table>
<table class="secondTable">
<tr>
<th class="secondTable">Customer ID</th>
<th class="secondTable">Total Sales</th>
</tr>
<tr>
<td class="secondTable">10001</td>
<td class="secondTable">$39.94</td>
</tr>
...
</table>
我知道有一个比不断重复“firstTable”和“secondTable”类更好的方法。
我尝试过这样的事情:
CSS:
#firstTable table
{
border: 1px solid black;
}
#firstTable th
...
然后
HTML:
<div id="firstTable">
<table>
...
</table>
</div>
但是没有用。
我错过了什么?
【问题讨论】:
标签: css html-table