Jump to content

Cellspacing in CSS - Solved!


Debbie-Leigh

Recommended Posts

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

 

Link to comment
Share on other sites

Another way you might want to try out is the following.

 

<style type="text/css">
.gorilla td, .gorilla th{display:inline-block; padding-right:5px;}
</style>

        <table class="gorilla">
            <thead>
                <tr><th>a</th><th>b</th><th>c</th></tr>
            <tbody>
                <tr><td>a</td><td>b</td><td>c</td></tr>
                <tr><td>a</td><td>b</td><td>c</td></tr>
                <tr><td>a</td><td>b</td><td>c</td></tr>
                <tr><td>a</td><td>b</td><td>c</td></tr>
                <tr><td>a</td><td>b</td><td>c</td></tr>
        </table>

By displaying them as block, we can give them some nice dimensions, including padding etc.

 

If you want to target the last column you might also want to have a look at something called <colgroup> 's

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.