我在我的頁面中有一個表格,我使用colgroups以同樣的方式格式化此列中的所有單元格,適用於背景顏色和所有單元格。但似乎無法弄清楚爲什麼文本對齊中心不起作用。它不會對齊文本居中。在colgroup中使用文本對齊中心
例如:
<table id="myTable" cellspacing="5">
<colgroup id="names"></colgroup>
<colgroup id="col20" class="datacol"></colgroup>
<colgroup id="col19" class="datacol"></colgroup>
<colgroup id="col18" class="datacol"></colgroup>
<thead>
<th> </th>
<th>20</th>
<th>19</th>
<th>18</th>
</thead>
<tbody>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
CSS:
#names {
width: 200px;
}
#myTable .datacol {
text-align: center;
background-color: red;
}
所以你說這是不可能的,他唯一的方法來實現這一點將是在TD元素本身然後 – Sander 2009-08-06 12:02:10
是的。我已經爲您的示例添加了一個修復程序,但如果表格變得更復雜,那麼這不起作用。 DisgruntledGoat提供了一些更多的解決方案。 – mercator 2009-08-06 13:07:38
這兩個關於內部失蹤tr的建議也是無效的。 th不屬於tbody,td不屬於thead。只需添加一個tr來包含th的內部thead。 – graywh 2010-11-12 15:18:36