我在我的页面中有一个表,我使用colgroups以相同的方式格式化此列中的所有单元格,适用于背景颜色和所有.但似乎无法弄清楚为什么文本对齐中心不起作用.它没有将文本对齐居中.
例:
<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>
Run Code Online (Sandbox Code Playgroud)
CSS:
#names {
width: 200px;
}
#myTable .datacol {
text-align: center;
background-color: red;
}
Run Code Online (Sandbox Code Playgroud)