RE: CSS Validation warning: You have no background-color with your color;

Jukka K. Korpela wrote:
> I'm afraid the documentation at
> http://jigsaw.w3.org/css-validator/
> is not maximally usable, since the most obvious place to
> look for info on problems is the "Docs" section, which is
> however quite technical. 
> I hope a link to the FAQ can be added there. It's not
> very intuitive 
> that you need to visit the "Feedback" section to find a
> FAQ. 

I did actually find the FAQ before posting the question on the list.
However...
 
> Anyway, the FAQ entry
> http://www.websitedev.de/css/validator-faq#color
> explains the issue, though rather compactly:
> "If you don't specify color and  background-color at the
> same level of specifity, your style sheet might clash
> with user style sheets." 

... I am not sure that I agree that the color has not been specified,
although I concur that tranparency indeed is not a color. Consider this
example:

<html>
  <head>
    <style>
      td { background-color: #00ff00; color: black; }
      td.level1 { background-color: #ff00ff; color: black; }
      td.level2 { color: black; } <-- No background color
      table { width: 100%; }
    </style>
  </head>
  <body>
    <table width="100%">
      <tr>
       <td class="level1">
         <table>
	      <tr>
              <td class="level2">&nbsp;</td>
            </tr>
          </table>
       </td>
     </tr>
    </table>
  </body>
</html>

Notice td.level2 has no background-color set. The background-color will be
that of the generic td element - green in this case. However, if you add
td.level2 { background-color: transparent; } it will render magenta, i.e.
the background-color of td.level1. Thus I have made a conscious choice as to
which background-color the td.level2 should render.


> Besides, it's not the whole truth. If you set background:
> transparent 
> for an element X contained in an element Y, expecting the
> background of Y to shine through, the assumption may fail
> because a user style sheet (or a browser style sheet, or
> another author style that will be combined with yours)
> sets background for Y. For all that you can know, the
> background color could be the same as or similar to the
> content color you set for X. (Specificity is just one of
> the factors that affect the question which CSS rule will
> be applied to an element if there is a conflict.)  

Well, usually the most comprehensive and perfected plan will have things run
smoothly - until you meet the enemy...

Received on Tuesday, 21 February 2006 16:10:12 UTC