17 replies [Last post]
z1p
Offline
Regular
Last seen: 15 years 41 weeks ago
Timezone: GMT-4
Joined: 2005-08-02
Posts: 11
Points: 0

Up until today my css layout has been being validated by the W3C css validator with no errors and no warnings. However, today I have been getting a warning of...

(Level : 1) You have no background-color with your color : .blue

The css was...

.blue {
color: #0000cc;
font-weight: bold;
}

when I got it. Before today it was not giving a warning. While I have valid css, I don't like getting the warning. I went ahead and changed the css to...

.blue {
background-color: transparent;
color : #0000cc;
font-weight : bold;
}

although I think it is silly to have to apply a background-color value, especially since this is only for coloring some text in the page.

When I added background-color: transparent, it still gives the same warning. Why is this? And again, why do I need to give a background color if I don't want to use one (I already have a background image and color for the body). In fact the CSS background page at W3 schools has transparent as a value on this page...

http://www.w3schools.com/css/css_background.asp

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 6 years 30 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

CSS validation question

Got a link to the page?

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

z1p
Offline
Regular
Last seen: 15 years 41 weeks ago
Timezone: GMT-4
Joined: 2005-08-02
Posts: 11
Points: 0

CSS validation question

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 6 years 30 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

CSS validation question

Hmmm, I see what you mean. I'm getting the same warnings for my site too where they weren't before. :?

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

z1p
Offline
Regular
Last seen: 15 years 41 weeks ago
Timezone: GMT-4
Joined: 2005-08-02
Posts: 11
Points: 0

CSS validation question

It just started. I was validating yesterday without the warnings. They must have changed something because I also got a warning about not having quote marks around new times roman in one of my elements.

I meant to put them in, but forgot on one element. Since I had coded that particular propery awhile back it was being missed, until today. That's why I'm thinking they have changed something. The WDG validator gives no warnings though.

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 6 years 30 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

CSS validation question

I'm wondering if someone with more of an inside knowledge can confirm this cos a quick check of some of the major CSS/XHTML sites that I refer to all come up with loads of warnings for the color/background-color thing.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 6 years 18 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

CSS validation question

It does appear that they have turned this check back on (way to go W3C more confusion)

These are accessibility checkpoints the errors are listed as [level 1] , [level 2]

I get a warning about absolute/ relative lengths in margins [level 2] and am told my stylesheet is not robust Sad

It always used to throw up an error on color as it was considered correct to specify a background to your text color for contrast and incase the user specified a black background when you had black text equally you are meant to specify a background color to any background images as well.

background transparent would still throw an error as transparent is the default state and as such does not represent a colour.

Clearly they have now re-included these points but noted against the WCAG guidelines 2.0

Time to check and fix all those sheets Smile

Edit: In fact looking closer I not only have warnings on missing background to foreground colors which I knew about anyway but more worryingly it is giving a warning on the same colors for background and foreground in unrelated rulesets for divs that will never exist on the same page :? this seems too pedantic and possibly unavoidable but I can't track this down now it's too late but I've got a feeling I'm not going to happy about it at all and even whether it's fixable as I don't think that it's strictly an error or something that needs warning on :mad:

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

z1p
Offline
Regular
Last seen: 15 years 41 weeks ago
Timezone: GMT-4
Joined: 2005-08-02
Posts: 11
Points: 0

CSS validation question

So if having background: transparent is giving a warning (thankfully not an error), what is the solution? Giving a color for the background when you already have a background image and background color for the entire page looks stupid.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 6 years 18 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

CSS validation question

N.B I should have been using the word Warning not Error as they do have two different meanings :roll:

You will need to repeat the background color in the other div.

No one said that the validator was perfect, it isn't I've still to find the time to look at what the "same color/background" warning was about when in reference to two rulesets that appear on completely different pages.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

z1p
Offline
Regular
Last seen: 15 years 41 weeks ago
Timezone: GMT-4
Joined: 2005-08-02
Posts: 11
Points: 0

CSS validation question

Hugo wrote:


You will need to repeat the background color in the other div.

Can you explain this for me in a little more depth? If I give it a background color (like I have already done for the page), then the blue font color will be on top of my background color which is on top of the body bacground image. That is what happens when I change...

.blue {
background: transparent;
color: #0000cc;
font-weight: bold
}

to

.blue {
background: #cccccc;
color: #0000cc;
font-weight: bold
}

Since I have a body background color for those who do not display images, I don't understand why the CSS can't just let it be the background color for all of my CSS unless I specify differently. It's not like my colored font will clash with the body background color if the user choses not to display the background image.

I guess it's not a big deal since these are only warnings, but a validator (especially the one from the standards organization) ought to be able to understand this.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 6 years 18 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

CSS validation question

Z1p I would then ignore the warning if your background has to be transparent to allow a parent background to show through, then don't worry too much about the warning.

Too a degree the warnings must be interpreted in context of your layout, they are not an exacting statement just a caution.

Don't worry in this instance too much, they seem to have re-jigged things with the Jigsaw validator and may well have introduced some errors (they have done so before). There is another thread which mentions the fact that suddenly the validator is throwing an error on line-height:0; which always used to be fine.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

drhowarddrfine
Offline
Leader
Last seen: 11 years 23 weeks ago
Timezone: GMT-6
Joined: 2005-05-21
Posts: 764
Points: 0

CSS validation question

Just found this on the w3c site faq about the css validator:

Quote:

Why does the validator complain You have no background-color with your color?

If you don't specify color and background-color at the same level of specifity, your style sheet might clash with user style sheets. To avoid this, specify always both of them, see Section 9.1 "Color Contrast" in the W3C Note "CSS Techniques for Web Content Accessibility Guidelines 1.0" or the article CSS Color Issues by the CSS Pointers Group for a discussion.

IE7 is 10 years behind the standards or wrong.
But it works in IE!
IE is a cancer on the web -- Paul Thurott

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 6 years 18 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

CSS validation question

It always was a case that you had to specify these combinations drhowarddrfine as I mention above and the Jigsaw validator used to check on this then seemed to stop and has now started again but rightly listed as accessibility checks now.

Question is why does it throw up a warning on unrelated id rulesets, it's being too pedantic.

It is something that you have to apply your own criteria to as it's a case that you do not always want a background declared.

I mentioned it on another thread as well:

http://www.csscreator.com/css-forum/ftopic12589.html&highlight=

Hugo

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Red Matrix
Red Matrix's picture
Offline
Regular
RGV
Last seen: 12 years 2 weeks ago
RGV
Timezone: GMT-5
Joined: 2005-09-17
Posts: 24
Points: 0

CSS validation question

Hmm, does this give a warning when you use it as a grandchild?

ie:

DIV #ID P { color: red; }

Dave

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 6 years 18 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

CSS validation question

Try it and see !

The validator is not intelligent it can't take into account the nesting of your elements which is why it throws a warning on every ruleset it finds with no pairing.

It does not think "hey the elements ancestor has a background and this element requires a transparent one to allow it to be seen, but with red text", it just throws a warning .

People should not overly worry about these warnings as long as they understand what they mean and have ensured that they are happy that contrast and user preference problems are covered.

It's one of those areas of accessibility that requires manual checks.

The validator would have been better of calling these not warnings but 'cautions' and possibly not listing every instance it comes across
but leaving it as note.

I predict they may disappear again.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

colindebink
Offline
newbie
Last seen: 15 years 33 weeks ago
Joined: 2005-09-26
Posts: 1
Points: 0

CSS validation question

hi, try this.
it won't give you an error or warning in the validator
and it has the same effect as transparent or an undefined bg color.

.blue {
background-color : inherit;
color : #0000cc;
font-weight : bold;
}

Cool

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 6 years 18 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

CSS validation question

Very good, so obvious that it didn't even occur to me.

However I would still be loath to go through a style sheet dropping in a rule that is in effect unnecessary bloating it out in order to appease the validator, this still remains a case that these matters are best left to manual checking and I for one would prefer them not to list every instance they find, it's rather annoying, especially pointing out errors such as no color with background on body, when in fact I have background color on the html, body group rules and color on the following body rule.

I have also noticed that it appears buggy with it's parsing of the rules for checking.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Nathan Smith
Offline
newbie
Last seen: 15 years 32 weeks ago
Joined: 2005-10-01
Posts: 1
Points: 0

CSS validation question

I've posted a write-up on my opinions of this problem.

Hopefully, if enough people comment, we can sway the opinion of the W3C...

http://sonspring.com/journal/css-validator-nonsense