Idontwantspam Posted November 17, 2007 Posted November 17, 2007 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.
PC_LOAD_LETTER Posted November 17, 2007 Posted November 17, 2007 would this do the trick?table.special tr.special td.special { color:#222222; background:#ffffff; text-align:center; font-Family:sans-serif; }
Idontwantspam Posted November 17, 2007 Author Posted November 17, 2007 Well, to further simplify that, you could just do .special {whatever}But the problem is, then I'd have to add class="special" to every single element - td, th, etc.
Chozo4 Posted November 17, 2007 Posted November 17, 2007 (edited) 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 {}orBODY TR, BODY TD {} Edited November 17, 2007 by Chozo4
Idontwantspam Posted November 18, 2007 Author Posted November 18, 2007 (edited) 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. UPDATE:It worked!! 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 November 18, 2007 by Idontwantspam
n0f3a6 Posted January 15, 2008 Posted January 15, 2008 (edited) <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 csshowz it possible???thnx Edited January 15, 2008 by n0f3a6
ripken204 Posted January 16, 2008 Posted January 16, 2008 (edited) bgcolor is just background-colorthere is no attribute for colspan Edited January 16, 2008 by ripken204
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now