1

What do you think is the most logical and efficient way to style a table in HTML/CSS? I've seen a lot of people using HTML properties in their code like

<table width="80%" cellspacing="2" border="0">
    <tr>
        <td align="right" nowrap="nowrap">
        </td>
    </tr>
</table>

Wouldn't it be easier to give tables and tds classes/ids and format them in an external stylesheet?

somazo
  • 133
  • 7

5 Answers5

1

Not only would it be better, it's the proper way to do this. The code you have now is not something you'd want on a production site.

John Halbert
  • 1,320
  • 2
  • 12
  • 23
0

You shouldnt use inline styles: quite good thread (What's so bad about in-line CSS?)
and if you dont like writing class for each, try :nth-child for styling (super useful): http://www.w3schools.com/cssref/sel_nth-child.asp

Community
  • 1
  • 1
Lukáš Gibo Vaic
  • 3,960
  • 1
  • 18
  • 30
0

Yes, It would.

However, when HTML was first being built, CSS was not as handy as it is now. With the abilities of CSS today, I would recommend creating the initial layout with HTML tags, and leaving any styling attributes (i.e. align, text wrap, border, etc.) to a CSS stylesheet.

Good Question!

Jacob Morris
  • 490
  • 1
  • 6
  • 16
0

there are lot of ways by using those you can style your table.

  1. inline Css
  2. internal CSs
  3. External Css(Mostly prefered)
  4. SASS(use Mixin)
  5. LESS
  6. Compass
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
0

The best and easy way to style a table is using CSS. You can see the example code below;

Code:

<style>
 .my_table{
     border:2px solid blue;
     width:50%;
     padding:5px;
 }
</style>
<table border="1" class="my_table">
 <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
 </tr>
 <tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
 </tr>

Ronald P Mathews
  • 2,178
  • 1
  • 22
  • 26