[web] [css] Cell padding and spacing for tables?

Started by
4 comments, last by deadimp 16 years, 10 months ago
Is there a way to set cellpadding and cellspacing via CSS? In my site, I want that each of these attibutes in <table> are 0 (which by default they aren't). I'm asking because currently, I'm using &#106avascript to scan through the document, and set the attributes.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Advertisement
The easiest way is to use "margin" and "padding" in the td definitions for the cells you want.
I do, but they don't 'cancel out' cellspacing and cellpadding. I set margin and padding in CSS, but Firefox still applies cellpadding and -spacing to it.
The main reason I'm asking is so that I can use margin and padding instead of the table-specific alternatives.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
I think it's called border-spacing and border-collapse in CSS. (Set border-collapse: collapse; to get the same effect as having cellpadding/spacing to 0)
<table cellspacing='0' cellpadding='0' border='0'>
<tr>
<td> one </td>
<td> two </td>
</tr>
</table>

/* CSS */
td {padding:4px;margin:2px;}

(That's if you are willing to set the 3 to zero...)
Mark A. Drake
OnSlaught Games
Mark Drake
I knew that you were able to manually set these in the tag, and that's what I had wanted to avoid.
This is the basics of the &#106avascript I'm using:
body_scan(function(e) { if (e.tagName=="TABLE") { e.cellPadding=0; e.cellSpacing=0; }} );

Where body_scan(), which is part of Thacmus, is just a function that scans through the body and throws this function against each of the elements.

I'm gonna go ahead and try Spoonbender's code.

EDIT: Thanks! That works.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire

This topic is closed to new replies.

Advertisement