Wednesday, February 20, 2008

Replacing 'cellpadding', 'cellspacing' and 'border' attributes for the table tag with CSS

I don't hate tables at all - unlike what pretty much all CSS proponents would have you do. They have their uses. What I don't like is adding cellpadding, cellspacing and border attributes in each table tag, making my mark-up look ugly and unreadable.
I recently found the really cool border-collapse CSS property, which seems to solve the issue. This post is just to fine-tune it and test it across browsers.

Unfortunately, inline style declarations (as in a <style></style> statement) seem to be unsupported by Blogger. So I guess I just have to have to paste screenshots.

FF 2.0.0.10

table_test_FF_2_0_0_10

IE 6

table_test_IE6

So, for a table with, say, class 'sample_table', this is what you need to do:

table.sample_table{border-collapse:collapse;} /*removes cellspacing and border*/
table.sample_table td{padding:0;} /*removes cellpadding*/

[just .sample_table will also work]