bestbuildpc: Forums
 

 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to set cellpadding and cellspacing in CSS?
 
 
Post new topic   Reply to topic    bestbuildpc Forum Index -> Web Development
View previous topic :: View next topic  
Author Message
bestbuildpc
Site Admin
Site Admin


Joined: Jun 30, 2012
Posts: 213
Location: NL

PostPosted: Tue Oct 07, 2014 1:44    Post subject: How to set cellpadding and cellspacing in CSS? Reply with quote

For controlling "cellpadding" in CSS, you can simply use padding on table cells. E.g. for 10px of "cellpadding":

Code:
td { 

    padding: 10px;
}


For "cellspacing", you can apply the border-spacing CSS property to your table. E.g. for 10px of "cellspacing":

Code:
table { 

    border-spacing: 10px;
    border-collapse: separate;
}


This property will even allow separate horizontal and vertical spacing, something you couldn't do with old-school "cellspacing".

Issues in IE <= 7

This will work in almost all popular browsers except for Internet Explorer up through Internet Explorer 7, where you're almost out of luck. I say "almost" because these browsers still support the border-collapse property, which merges the borders of adjoining table cells. If you're trying to eliminate cellspacing (that is, cellspacing="0") then border-collapse:collapse should have the same effect: no space between table cells. This support is buggy, though, as it does not override an existing cellspacing HTML attribute on the table element.

In short: for non-Internet Explorer 5-7 browsers, border-spacing handles you. For Internet Explorer, if your situation is just right (you want 0 cellspacing and your table doesn't have it defined already), you can use border-collapse:collapse.


Code:
table { 

    border-spacing: 0;
    border-collapse: collapse;
}
  
Back to top
View user's profile Send private message Visit poster's website
bestbuildpc
Site Admin
Site Admin


Joined: Jun 30, 2012
Posts: 213
Location: NL

PostPosted: Tue Oct 07, 2014 1:48    Post subject: Reply with quote

border-collapse

This declaration takes two values:


separate: keep borders separate. This is the default.
collapse: merge borders of adjoining cells.

Code:
<table style="border-collapse: collapse">


border-spacing

border-spacing is cellspacing translated to CSS. Note that it needs a unit.



Code:
<table style="border-spacing: 10px;">
  
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    bestbuildpc Forum Index -> Web Development All times are GMT + 2 Hours
 
 Page 1 of 1

 

Jump to:   
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001-2008 phpBB Group
 
Forums ©