CSS中如何设置列宽在Web开发中,常常需要设置表格的列宽。在CSS中,我们可以使用属性width来设置列的宽度。例如,我们有一个表格如下: 名称 数量 价格 苹果 10 2.00 橘子 5...
CSS中如何设置列宽
在Web开发中,常常需要设置表格的列宽。在CSS中,我们可以使用属性width来设置列的宽度。
例如,我们有一个表格如下:
<table>
<tr>
<th>名称</th>
<th>数量</th>
<th>价格</th>
</tr>
<tr>
<td>苹果</td>
<td>10</td>
<td>2.00</td>
</tr>
<tr>
<td>橘子</td>
<td>5</td>
<td>1.50</td>
</tr>
</table> table {
width: 220px; /*表格总宽度*/
}
th:nth-of-type(1) {
width: 100px; /*第一列宽度为100px*/
}
th:nth-of-type(2) {
width: 50px; /*第二列宽度为50px*/
}
th:nth-of-type(3) {
width: 70px; /*第三列宽度为70px*/
}