Re: missing background-color

On Sun, 13 Nov 2005, Ian Hickson wrote:

> The initial value of 'background-color' is 'transparent', not 'inherit'.

Thanks for the correction. The basic problem is the same: by setting the 
background-color property to either of these values or defaulting it
means that you get whatever background is specified for the parent 
element. And that's not under the author's control; he may say something
about it, but his opinion may be overruled. That's natural, but problems 
arise when the author has suggested content color and this suggestion is
_not_ overruled.

> The problem is that an
> element with a color set and not a background color set can have a color
> and background color set from a user stylesheet, where the end result has
> the element's color coming from the author stylesheet and the background
> color coming from the user stylesheet, and since those colors were picked
> by different people they might be the same and make the text go invisible.

Indeed. This what most authors seem to miss, when this issue is discussed.

> The solution is to set 'background: transparent' whenever setting 'color',
> if you have colors set all the way back to the root element (explicitly as
> 'background: transparent; color: inherit' if you want the default
> behaviour); otherwise, the solution is to set both 'background' and
> 'color' to non-transparent, non-inherit values.

I'm afraid only the latter solution is reliable. One reason to this is 
that the value 'inherit' is not supported by the most common browser.
Using 'transparent', even when set explicitly, isn't reliable either, for
a different reason.

Suppose that you have just <body>, <p> and <strong>, nested in the obvious 
way. If you set
strong { color: black; background: transparent; }
then what happens if the user style sheet is
body, p { background: black; color: white; }
which is, as such, a technically correct style sheet. (If you wonder why
anyone would use it, think about all the authors that seem to love
black background. Surely they may some day invent the possibility of
looking at others' pages that way too. Besides, there are people with
a rare vision impairment that makes it easier to read white on black than
black on white.)

If you set
strong { color: black; background: yellow; }
for example, there will still be problems if a user style sheet has, say,
strong { color: yellow; }
but this is a technically wrong style sheet and it is a problem that
the user created and needs to solve. Authors should take precautions
against all imagineable _correctly written_ browser/user style sheets.

-- 
Jukka "Yucca" Korpela, http://www.cs.tut.fi/~jkorpela/

Received on Sunday, 13 November 2005 19:42:57 UTC