Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the right way to size html columns?

Tags:

html

css

xhtml

Simple question, I was wondering, what in 2011 is the right way to size html tables? (containing tabular data, of course!)

Should the following still be the way to go?

<tr>
    <th width="45%">Name</th>
    <th width="10%">Author</th>
    <th width="20%">Description</th>
    <th width="10%">Rating</th>
    <th width="15%">Download</th>
</tr>

Or would it be better to give each column an ID (or class) and set its width with CSS?

Thank you for your input!

like image 530
Mathieu M-Gosselin Avatar asked Dec 06 '22 00:12

Mathieu M-Gosselin


1 Answers

You can use col or colgroup for that purpose.

<table>
  <col class="x"/>
  <col class="y"/>
  <col class="z"/>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td>$53</td>
  </tr>
</table>

...and apply styles to the classes:

col.x {
   ...
}
like image 80
Carles Barrobés Avatar answered Dec 07 '22 13:12

Carles Barrobés