Jukka K. Korpela wrote:
Note, by the way, that people who posted you some sample codes forgot to set
the background.
I didn't forget, I omitted it deliberately as being inappropriate.
There is no reason to set background colour in every CSS block. There's
no reason why every time colour is set, background colour needs to be
set too. The need is to ensure that unviewable combinations don't
arise. This can be achieved by crudely setting in pairs, or by by
carefully studying the overall stylesheet.
Usually it's a good idea to set both. Most uses of CSS blocks are
driven by applying the whole block to an element in a fairly simple
manner, with a "blanket" set of rules to apply. Setting only one
colour here would be likely to cause conflicts with inherited
backgrounds etc.
In this case though, the CSS is a little more obscure. We're applying a
simple "highlight" by actively controlling only one color. The other
color _should_ be left as inherited - we have no interest in changing
it. It's also a problem from maintenance reasons if we did set the pair
of colours. This breaches the good software principle of "Don't Repeat
Yourself" which is just as important as the CSS principle of "Don't set
only one colour next to an unknown inherited background".
It's necessary to know the scope in which this CSS rule is used. It's
necessary to know that the backgrounds possible in this scope can't
generate a conflict with the possible colours. If these conditions are
met by studying the page design, then there's no reason to duplicate a
hard-coded background setting into every block.
Of course this isn't perfect, in the case of some heavyweight user
stylesheet colour and background settings. But nor is the "set
everything twice" behaviour.