By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,543 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,543 IT Pros & Developers. It's quick & easy.

Why is it important that I define background-color for validated CSS

P: n/a
Hi,

I am running a w3c CSS validation check on a site in development. I
have many errors saying that my CSS is not valid because I have not
defined the background-color but instead left it default transparent.
Why does it require that every CSS defined element have their
background-color defined?

Also, when I set styles in the following way:

#div {
background: #FFF url('images/bg.gif');
}

....it still gives me an error saying that I havent defined
background-color. Is the above an invalid way of writting it?

Thanks

Burnsy

Feb 7 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

bissa...@yahoo.co.uk wrote:

I am running a w3c CSS validation check on a site in development. I
have many errors saying that my CSS is not valid because I have not
defined the background-color but instead left it default transparent.
Warnings, not errors.
Why does it require that every CSS defined element have their
background-color defined?
Imagine the following author stylesheet:

body {color: black; background: white}
p {color: blue; background: transparent;}

and the user stylesheet
body {color: white !important; background: black !important;}

In that case the paragraphs will have blue text on a black background
(yuck). If the author had specifed
p {color: blue; background: white;}
then it would be okay.

Now, this is a problem when background images are used as due to tiling
you don't want to respecify them for every element.

In general, few people use user stylesheets and those that do are
usually savvy enough to write them carefully (e.g. liberal use of the
universal selector * helps) and use browsers or browser extensions that
let them toggle either the author or user css off entirely when
problems crop up.

So this is an issue that you should be aware of and which you should
think about, but it is only a warning not an error, so consider
yourself warned and if you want to carry on regardless, do so.
Also, when I set styles in the following way:

#div {
#div? Is 'div' really a useful unique identifer?
background: #FFF url('images/bg.gif');
}

...it still gives me an error saying that I havent defined
background-color. Is the above an invalid way of writting it?


I can't reproduce that error/warning with my stylesheet that contains
the line
body { background: #91C4D9 url("bg-blue.gif") fixed; color: #000;}
Can you post the URL of your stylesheet so other people can validate
it?

Steve

Feb 7 '06 #2

P: n/a
<bi******@yahoo.co.uk> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi,

I am running a w3c CSS validation check on a site in development. I
have many errors saying that my CSS is not valid because I have not
defined the background-color but instead left it default transparent.
Why does it require that every CSS defined element have their
background-color defined?
If you set one colour then set them all. If you don't then it isn't a
validation error, just bad practice.

If my browser was set to display white text on a black background and I
visited a site where the text was set to black and the background colour
hadn't been set then the page would be black text on a black background.
Also, when I set styles in the following way:

#div {
background: #FFF url('images/bg.gif');
}

...it still gives me an error saying that I havent defined
background-color. Is the above an invalid way of writting it?


If I feed your CSS snippet through the W3C CSS validator then it comes up
with this message: "Line : 1 (Level : 1) You have no color with your
background-color : #div"

The background colour *has* been set but you haven't set any foreground
colour.
eg: #div {background: #FFF url('images/bg.gif'); color:#000000}
Feb 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.