Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

over writing bgcolor defined in body tag

Status
Not open for further replies.

spicymango

Programmer
May 25, 2008
119
CA
Can I do something in css that will over write my bgcolor definded in the body tage. I don't want to go and make change all over the website and change all by 100 some pages

Code:
<BODY BGCOLOR="#ffffff" TEXT="#000000" TOPMARGIN=0 LEFTMARGIN=0 MARGINHEIGHT="0" MARGINWIDTH="0">
 
You could try:

Code:
body {
   background-color: #CC0000 !important;
}

If that doesn't work, then you'd need to remove all BGCOLOR attributes - but that's no bad thing, as you should really be using CSS anyway.

That, and global search-and-replace is easy with most IDEs or Textpad, anwyay.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks a lot, what is the significance of "important"?

I noticed even
Code:
background-color: #CC0000;
works

other thing is it possible to put an image and set certain color both as background. Something like

body {
background-color: #CC0000 !important;
background: url(back.gif) center top;

}

I have a small image that I want in the middle as background, remaining area #CC0000 color
 
Important means that the particular attribute set right there should have preference over the others. With !important, your code should actually work. You didn't need important in the original code, because any other colour was specified within HTML and CSS will always take preference over HTML attributes. If you would have background defined somewhere else in the stylesheet, you might have to add !important to override that value.

With the latter code, you need to understand the "background" shorthand, which can be used to define all aspects of the background in the following order: colour, image, repeat, attachment and position. Omitting any of these properties in the shorthand, will set it to the default value. So in your code, you first define the background colour and then reset it. You could either:

1. Add all values to one line as background shorthand.
2. Add individual lines for background-color, background-image and background-position.

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top