[web] [css] Cell padding and spacing for tables?
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 javascript to scan through the document, and set the attributes.
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.
The main reason I'm asking is so that I can use margin and padding instead of the table-specific alternatives.
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...)
<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...)
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 javascript I'm using:
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.
This is the basics of the javascript 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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement