views:

253

answers:

5

Is it ok to use cellpadding="2" cellspacing="2" in ? of these are not recommnded by W3C and not right according to web standards?

What are alternative in CSS?

Update and is it also ok to use

<td align="right" valign="top">?

My question is in terms of separation of content and presentation and w3c recommendations.

Update:

According to this chart in <table> only align and bgcolor are not allowed in Strict version. So is it ok to allow other properties of <table>

alt text

+1  A: 

See following:
http://stackoverflow.com/questions/339923/how-to-set-cellpadding-cellspacing-in-css

Brij
This should be a comment, not an answer.
kemp
A: 

The cell-padding and cell-spacing properties are still fully supported. Although some people will tell you to do it with CSS setting padding and margin on the table cells, this is still the easy way to have it applied to every cell in a table.

If you want a list of properties and which ones are deprecated, I find w3schools to be the most reliable source of information.

w3schools: td tag

w3schools: table tag

animuson
you mean cell-padding and cell-spacing not deprecated and valid.
metal-gear-solid
Yes, if it is not deprecated, then it is fine to use. If you knew the definition of deprecate: to express earnest disapproval of. If it's not deprecated, it is therefore not disapproved of.
animuson
Note that while the attributes are valid in HTML4, they will be obsoleted by HTML5. http://dev.w3.org/html5/spec/obsolete.html#non-conforming-features
Alohci
A: 
<style type="text/css">
table.padded-table td { 
    padding:10px; 
    }
</style>
muruga
+1  A: 

Imagine if you had several tables across several pages and you wanted to change the padding or the spacing for one reason or another. Well, you would have to go through your entire site and make the changes. Or by using CSS you can change your entire site by changing two lines of code. This is not only far more efficient, but it also helps you avoid making mistakes. CSS offers you more flexibility and control and I would recommend using it.

<style type="text/css">
table td {padding:10px; margin:10px;}
</style>

Play around with the pixel values and see what results you get and what you prefer. If you want to use some tables with padding and margins, and other without, you can create classes in your CSS by adding a "." before a name of your choice:

<style type="text/css">
.myTable td {padding:10px; margin:10px;}
</style>

Note that class names are case sensitive. There are also many other attributes you can have fun with like border, background-color, background-image, etc...

Short answer: While cell-spacing and cell-padding attributes are not depreciated, it would be better to use CSS for consistency across your site.

Mel
A: 

No, the attributes are not officially deprecated but they are generally frowned upon, since you should use CSS for presentation.

For cellpadding you can easily replace it with padding in CSS:

table.classname td {
  padding: 4px;
}

For cellspacing, first decide if it's really necessary. If you don't have any borders on the table cells, or you don't want spacing between the borders of each cell then it isn't. (Personally I think cell spacing looks bad design-wise, but it may be useful in some circumstances.)

It's quite nice to do this:

table {
  border-collapse: collapse;
}

Then each table cell shares the border with its neighbour, meaning you can add, say, 1px top and bottom borders and you just get 1px separating each row.

To separate borders, however, you can use this CSS, though it probably doesn't work in IE6.

table.data td {
  border-collapse: separate;
  border-spacing: 4px;
}
DisgruntledGoat