what is the proper way to style columns width in table?
How to style this table so that first column is X pixels wide and second Y pixels wide. What is the best way to style it? I guess adding class to every TD is not the way to go. Should I use COL and style 开发者_如何转开发it?
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
CSS is the proper way to style HTML.
Use CSS class names as you normally do on other tags.
<table>
<tr>
<td class='col1'></td>
<td class='col2'></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
CSS:
.col1 {
width:100px
}
.col2 {
width:120px
}
Depending on your browser support requirements, you might consider styling a colgroup. For tables, I've always just set the width
on the td
s in the first row.
精彩评论