Forum Moderators: not2easy

Message Too Old, No Replies

changing table color with css

overriding table bgcolor attribute

         

eveningwalk

6:22 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



I have a table with the table attribute bgcolor="#cccccc" - Now I'd like to change the bgcolor to #999999 using CSS, without changing the bgcolor attribute in the table tag. So I add an id attribute to the table, like

<table bgcolor="#cccccc" id="newcolor">

and change the color in #newcolor in the stylesheet. However, this doesn't seem to change the table color.

So is there a way to change/override the table color in the table bgcolor attribute using CSS?

Thanks,
ew

D_Blackwell

6:32 pm on Dec 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This seems to override just fine in Firefox, Opera, and IE.

Curious - Why not drop the bgcolor?

<head>
<style>
table#newcolor {
background-color: #999;
}
</style>
</head>
<body>
<table bgcolor="#cccccc" id="newcolor">
<tr>
<td>
test
</td>
<td>
test
</td>
</tr>
<tr>
<td>
test
</td>
<td>
test
</td>
</tr>
</table>
</body>

coho75

6:38 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



If the same style is defined with different values in different style sheets, the the order of precedence is

1. Inline Style Sheets
2. Internal Style Sheets
3. External Style Sheets

Because you are defining bgcolor inline, it is over-riding the external sheet.

D_Blackwell

6:57 pm on Dec 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The order of precedence doesn't apply in this case. The correct declaration will work inline, internal, or external.

eveningwalk

10:02 pm on Dec 5, 2005 (gmt 0)

10+ Year Member



Yes, it works! So indeed the CSS overrides the table bgcolor attribute. As for dropping the bgcolor attribute, I'll need a search and replace tool - as I have over 5000 pages. Any suggestions for a search and replace tool?

Thanks,
ew

Mobull

12:06 pm on Dec 8, 2005 (gmt 0)

10+ Year Member



Search and replace? I always use Dreamweaver :)
You can use it to change the current document, the current site or e.g. all files in a folder on your pc.