Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Avoiding loops

0 views
Skip to first unread message

Emanuele D'Arrigo

unread,
Sep 28, 2009, 10:35:19 AM9/28/09
to
Hello again,

I've been wondering: how does mozilla's layout avoid potential css
loops? Take this two css rules:

div[style="color:blue"] {color:red}
div[style="color:red"] {color:blue}

Admittedly, this would not exactly be a sensible thing to do. But what
prevents a sensibility-lacking individual from generating a loop in
which a div's color is set to blue which the css-handling
functionality then sets to red which is then set back to blue again
and so on, ad infinitum? Sorry if it's a bit of a silly question...

Manu

Martijn

unread,
Sep 28, 2009, 10:52:28 AM9/28/09
to Emanuele D'Arrigo, dev-tec...@lists.mozilla.org
On Mon, Sep 28, 2009 at 4:35 PM, Emanuele D'Arrigo <man...@gmail.com> wrote:
> Hello again,
>
> I've been wondering: how does mozilla's layout avoid potential css
> loops? Take this two css rules:
>
> div[style="color:blue"] {color:red}
> div[style="color:red"] {color:blue}

This wouldn't cause a loop, inline styles (style="color:red") have a
higher specifity than selectors in a style block.
See also http://www.w3.org/TR/CSS2/cascade.html#specificity for some more info.

Regards,
Martijn

> Admittedly, this would not exactly be a sensible thing to do. But what
> prevents a sensibility-lacking individual from generating a loop in
> which a div's color is set to blue which the css-handling
> functionality then sets to red which is then set back to blue again
> and so on, ad infinitum? Sorry if it's a bit of a silly question...
>
> Manu

> _______________________________________________
> dev-tech-layout mailing list
> dev-tec...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-layout
>

--
Martijn Wargers - Help Mozilla!
http://quality.mozilla.org/
http://wiki.mozilla.org/Mozilla_QA_Community
irc://irc.mozilla.org/qa - /nick mw22

Daniel Holbert

unread,
Sep 28, 2009, 12:37:41 PM9/28/09
to Emanuele D'Arrigo, dev-tec...@lists.mozilla.org
On 09/28/2009 07:35 AM, Emanuele D'Arrigo wrote:
> div[style="color:blue"] {color:red}
> div[style="color:red"] {color:blue}
>
[snip]

> div's color is set to blue which the css-handling
> functionality then sets to red which is then set back to blue again
> and so on, ad infinitum? Sorry if it's a bit of a silly question...

Hi Manu,

These rules wouldn't create a loop, for a more basic reason than the
specificity issue that Martijn brought up: the [style="color:blue"] only
matches elements using the *style attribute*, not the computed style.
(You seem to have confused those two -- the style attribute is a standard
HTML attribute, and it doesn't change, aside from direct modifications via
scripting. The Computed Style, on the other hand, includes the results of
the whole style cascade.)

e.g. consider this element:

<div style="color:blue"></div>

*Only* your first rule would ever apply here, because the element's style
attribute exactly matches that rule's selector. Now, even if the first
rule changed the computed style[1], it won't change the element's *style
attribute*. So your second CSS rule *never* applies to this example div,
and there's no loop.

~Daniel

[1] In this case, it won't actually change the computed style, because of
the rule-specificity priorities that Martijn brought up.

Emanuele D'Arrigo

unread,
Sep 29, 2009, 7:12:10 AM9/29/09
to
Martijn, Daniel, thank you for the very informative replies, much
appreciated!!!

Manu

0 new messages