Re: Fwd: [CSS3] Conditional statements in CSS 3

"Gabriele Romanato" <gabriele.romanato@gmail.com> wrote:

> ---------- Forwarded message ----------
> From: Gabriele Romanato <gabriele.romanato@gmail.com>
> Date: 15-ott-2007 13.12
> Subject: [CSS3] Conditional statements in CSS 3
> To: www-style-request@w3.org
> 
> Dear all,
> while I was writing an user style sheet that emulates the behavior of Lynx
> browser, it came to my attention the following problem:
> 
> img[alt]:before {
> content: attr(alt) !important;
> }
> 
> img[src]:before {
> content: attr(src) !important;
> }
> 
> In other words, it's not possible to choose between the above mentioned
> options.

When rules of equal specificity exist, the order of rules in the stylesheet
is the determining factor.  There is no ambiguity here.

> I propose the following new keyword for the at-rules
> 
> @if (img[src]) {style rules}
> 
> @else if (img[alt]) {style rules}
> 
> we can check now if there's such an attribute.

This is exactly what your two rules already specify.  The property values in
the img[src]:before rule beat the img[alt]:before rule's properties.  See
point 4 in section 6.4.1 of the CSS 2.1 document:

http://www.w3.org/TR/CSS21/cascade.html#cascading-order


If you want to explicitly say that the img[alt] version only applies when
there's no src attribute, you could always write it like this:

img[alt]:not([src]):before

but that's a CSS3 Selectors feature, not CSS2.1, so CSS2.1 user agents will
reject this rule completely.


-- 
Stewart Brodie
Software Engineer
ANT Software Limited

Received on Monday, 15 October 2007 11:40:56 UTC