Jump to content
  • Advertisement
Sign in to follow this  
deadimp

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

This topic is 4161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
The easiest way is to use "margin" and "padding" in the td definitions for the cells you want.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
<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...)

Share this post


Link to post
Share on other sites
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:
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!