Help - Search - Members - Calendar
Full Version: Tables in CSS
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
Idontwantspam
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. newwink.gif
geek
would this do the trick?
CODE
table.special tr.special td.special { color:#222222; background:#ffffff; text-align:center; font-Family:sans-serif; }
Idontwantspam
Well, to further simplify that, you could just do
CODE
.special {whatever}

But the problem is, then I'd have to add class="special" to every single element - td, th, etc.
Chozo4
Do the reverse in this case as it will tailor to your needs:
CODE
.special {}
.special tr {}
.special td {}


If you wish to combine it all into a single line with all matching attributes...
CODE
.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.
CODE
TABLE, TR, TD {}

or
CODE
BODY TR, BODY TD {}
Idontwantspam
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. welcome.gif

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

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.
n0f3a6
QUOTE
<tr><th colspan="4" bgcolor="#87a966"> <b><a href="http://www.hotmail.com/">Hotmail</a></b><th><tr>


i wanna get colspan & bgcolor of <th> into a css

howz it possible???

thnx
ripken204
bgcolor is just background-color
there is no attribute for colspan
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.