CSS Table

greg's picture

He has: 1,581 posts

Joined: Nov 2005

How do I remove the default borders on a table using CSS?
Is it the cell or row that has a default border?

Applying a background colour to the table isn't enough in this case, as I have different coloured cells.

I tried border: 0px; and border: 0; which didn't work. I could give the td'd a border of the same colour of that cell, which would work, but that sounds a bit 'quirky', as I actually don't want any borders.

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

It's the table cells that have the border applied, and I believe the <table> itself as well.

Did you try border: none; ?

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Yeah I tried that.

I eventually got it working with border-spacing: 0px; on the table CSS.
I guess it was the cellpadding Doh!

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

If you use Firefox + Firebug + Web Developer/Edit CSS you can quickly read the existing styles and edit them...SmileyCentral.com

greg's picture

He has: 1,581 posts

Joined: Nov 2005

I have 3 virtual servers running local, so it's easy to edit CSS stylesheet then refresh browser.
That way when it's working as desired I have the stylesheet complete, rather than having to get it from the firebug code Wink

But yeah, for online edits I use Firebug, didn't I tell you about that...

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

greg wrote:
But yeah, for online edits I use Firebug, didn't I tell you about that...

I develop sites locally using xampp and I use Firebug locally too.

I work with a few designers who use Dreamweaver and give me those horribly nested tables... in many cases I can ignore them and just insert my code where needed, but sometimes when the designer says "pull it up 10px" it can take me an hour to figure out how to di it without creating a gap in a background or something...

@Megan - many platforms (Drupal, WordPress) set border-collapse: collapsed by default; sometimes it can be enabled for certain effects.

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

Oh, were you trying to get rid of the spacing and not the border lines? I just did a test and realized that there are no default border lines. Shows you how often I work with tables!

border-collapse: collapse would work for this as well. Check out the spec on border models:

http://www.w3.org/TR/CSS21/tables.html#borders

greg's picture

He has: 1,581 posts

Joined: Nov 2005

Megan wrote:
Oh, were you trying to get rid of the spacing and not the border lines? I just did a test and realized that there are no default border lines. Shows you how often I work with tables!
I work with them very rarely too, which is why I thought it was some sort of default border, and not the default cellpadding.

My initial thought was a table would be simple and easy for the data from the DB in a shopping cart.
Then from fighting with it I remembered all the issues using CSS on tables, and that using DIV's are actually just as easy if not easier Doh!

Ahh well, all look pretty now anyway.
Cheers

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.