...

View Full Version : Cellspacing in CSS - Solved!



Debbie-Leigh
08-02-2011, 02:04 AM
Hi,

At long last, I've managed to figure out how to emulate the HTML cellspacing attribute in CSS. So I thought that I'd post it here so everyone can use it.

Here's the code:


.cellspacing td {
border-right : 3px solid #FFF;
}
.cellspacing td:last-child {
border-right : 0px;
}
.cellspacing th {
border-right : 3px solid #FFF;
}
.cellspacing th:last-child {
border-right : 0px;
}


Just add the cellspacing class to a table tag and it creates a white 3px border between each column throughout the table.

It's a shame the CSS designers haven't made this easier by having a proper built-in cellspacing attribute, but until they do, this is the next best thing, I guess.

Enjoy.

Debbie

Sammy12
08-02-2011, 03:11 AM
http://www.webdeveloper.com/forum/showthread.php?p=1166358#post1166358

http://www.codeguru.com/forum/showthread.php?p=2026879

seems a lot like advertising

---

all your posts do

http://www.google.com/search?rlz=1C1CHOL_enUS415US415&sourceid=chrome&ie=UTF-8&q=I'm+trying+to+get+top+both+corners+of+my+table+header+row+to+have+a+rounded+corner+each%2C+but+onl y+one+is+appearing.

slippery one

Debbie-Leigh
08-02-2011, 10:17 AM
Hi Sammy12,

No, not advertising, just giving something back to all the forums (fora?) that I've used over the years.

It may not work with some older versions of some browsers, though, because the :last-child pseudo class has only just become supported in some of them, which I guess is why it's only now that I've be able to find this solution.

Debbie

VIPStephan
08-02-2011, 12:11 PM
It's a shame the CSS designers haven't made this easier by having a proper built-in cellspacing attribute, [Ö]

Have you never heard of the border-spacing (http://www.quirksmode.org/css/tables.html#borderspacing) property?

Sammy12
08-02-2011, 06:32 PM
Hi Sammy12,

No, not advertising, just giving something back to all the forums (fora?) that I've used over the years.

It may not work with some older versions of some browsers, though, because the :last-child pseudo class has only just become supported in some of them, which I guess is why it's only now that I've be able to find this solution.

Debbie

that's good to hear. i just can't stand when i spend my time reading a post and find it's commercial. there's a fine line between a post like this and commercial use. I just hope that line stays 1px solid.

Debbie-Leigh
08-02-2011, 08:39 PM
Hi Sammy12,

:-) Yes, I hope so too.

Hi VIPStephan,

Yep, tried it, but it only produces a border around the table, not between cells in the same way that cellspacing does. That's one reason why I ended up with this solution.

There may be other ways to achieve the same effect, but this is the one I've found that works, so I thought I'd share it, so others who have also been tearing their hair out don't have to anymore.

Debbie

VIPStephan
08-02-2011, 08:51 PM
Hi VIPStephan,

Yep, tried it, but it only produces a border around the table, not between cells in the same way that cellspacing does.

That canít be true. In which browser (and version) have you experienced this? Look again at the link I provided above. The cells displayed there are all separate for me in Firefox 5.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum