Jump to content

Tables in CSS


Recommended Posts

I'm wondering if there's any way to change the style of all of a table's cells using CSS. When I use class= on the whole table, only the table itself gets those properties - for example, the border shows up on the outside of the table only, and padding only affects the outermost border, not each individual cell. It is also of course possible to apply a style to all <td> elements, but I want to be able to use classes to have different styles of tables, but I don't want to have <td class="table1"> everywhere. So the question is, can I somehow apply a class to the table and have all cells in the table follow a certain style based on that? Maybe there's some sort of pseudo-class that I'm missing. Anyway, if someone can help, I'd appreciate it. Thanks. ;)

Link to comment
Share on other sites


Do the reverse in this case as it will tailor to your needs:

.special {}
.special tr {}
.special td {}

If you wish to combine it all into a single line with all matching attributes...

.special, .special tr, .special td {}

With this you'll need but a single class= in your table tag and that is all.

Some much older browsers (NetScape Navigator 4.x for example) however will not like this and will not render the <td>'s through this css unless you treat the tr's indivually in this way. Which would involve tagging the <tr>'s with a class if you wish to render the <td>'s through CSS using '.special TD'.

Additionally, if you are making ALL tables/cells/rows the same colour and want to make them all conform to your CSS, you can do a quick and diry way for it without any classing.

TABLE, TR, TD {}

or

BODY TR, BODY TD {}

Edited by Chozo4
Link to comment
Share on other sites

OK, I'll try that. That looks like pretty much exactly what I was looking for. I hope it works!

Thanks... I'll let you all know how it works. :hello:

UPDATE:

It worked!! :thumbup Thanks - you've just saved me a lot of work and frustration. :)

Oh, and it doesn't matter for the older browsers - according to the site logs, most of our users are on IE 6 or 7, Firefox 1 or 2, Safari or Opera. All of these browsers seem to render it fine, and for any browsers with issues, it'll still show up, just not quite perfectly.

Edited by Idontwantspam
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...