In an HTML table, the cellpadding and cellspacing can be set like this:
<table cellspacing="1" cellpadding="1">
How can the same be accomplished using CSS?
|
In an HTML table, the
How can the same be accomplished using CSS? |
||||
|
Basics For controlling "cellpadding" in CSS, you can simply use
For "cellspacing", you can apply the
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 In short: for non-Internet Explorer 5-7 browsers,
Note: For a great overview of CSS properties that one can apply to tables and for which browsers, see this fantastic Quirksmode page. |
|||||||||||||||||||||
|
DefaultThe default behavior of the browser is equivalent to:
CellpaddingSets the amount of space between the contents of the cell and the cell wall
CellspacingControls the space between table cells
Both
Both (special)
Here you can find the old html way of achieving this. |
|||||||||||||||||
|
|
|||||||||||||||||||||
|
|
Setting margins on table cells doesn't really have any effect as far as I know. The true CSS equivalent for You can use |
|||||||||
|
|
This hack works for Internet Explorer 6 and later, Google Chrome, Firefox, and Opera:
The
|
|||||
|
|
For those who want a non-zero cellspacing value, the following CSS worked for me, but I'm only able to test it in Firefox. See the Quirksmode link posted elsewhere for compatibility details. Seems it may not work with older Internet Explorer versions.
|
||||
|
|
|
The simple solution to this problem is:
|
||||
|
|
|
Also, if you want |
|||
|
|
|
Wrap the contents of the cell with a div and you can do anything you want, but you have to wrap every cell in a column to get a uniform effect. For example, to just get wider left & right margins: So the CSS will be,
Yes, it's a hassle. Yes, it works with IE. In fact, I've only tested this with IE, because that's all we're allowed to use at work. |
|||||
|
|
TBH. For all the fannying around with CSS you might as well just use Anyone else suggesting margins on |
|||||
|
|
Just using |
||||
|
|
|
This style is for Full Reset for tables - cellpadding, cellspacing and borders. I had this style in my reset.css file:
|
||||
|
|
|
From what I understand from the W3C classifications is that Based on that I found it a lot easier to create a It works on Chrome, IE(6 and later) and Mozilla(2 and later). Margins are used (or meant anyways) to create a spacer between container elements, like |
|||||
|
|
||||
|
|
|
Simply use CSS padding rules with table data:
And for border spacing:
However, it can create problems in older version of browsers like Internet Explorer because of the diff implementation of the box model. |
||||
|
|
|
CSS:
|
||||
|
|
|
Try this:
Or try this:
|
||||
|
|
|
I used
and it works for me in IE7. It seems to override the cellspacing attribute. |
|||||||||
|
|
||||
|
|
if |
||||
|
|
|
For table cellspacing and cellpadding are obsolete in HTML 5. Now for cellspacing you have to use border-spacing And for cellpadding you have to use border-collapse. And make sure you don't use this in your HTML5 code. Always try to use these values in CSS-3 file. |
|||
|
|
|
How about adding the style directly to the table itself? This is instead of using
|
|||||||||||||||||||||
|
|
||||
|
|
|
In an HTML table, the For Cell-Padding:
Just call simple EX:
For Cell-Spacing Just call simple EX:
More table style by CSS source link here you get more table style by css |
|||||
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
width:autothenborder-collapsemight not work as expected. – PJ Brunet Sep 1 '16 at 7:12