[whatwg] Selectors within <style scoped>

Hi all,

According to the HMTL5 spec, selectors are not limited to children of the
scoping element (the parent element of <style scoped>). For example:

<div class="foo">
    <div>
        <style scoped>
            .foo p { display: none }
        </style>
        <p>To be or not to be, that is the question.</p>
    </div>
<div>

In above snippet, the selector in the scoped stylesheet would match, causing
the <p> element to be hidden. To me, this seems counterintuitive - I
originally would have the scoped stylesheet expected to be matched starting
from the scoping element (the 2nd <div> in above example) downwards, and not
cross the scope boundary.

As far as I can tell, the advantages of allowing the selector to cross the
boundary are:

1.) less change to selection behavior
2.) allow the styling to change depending where the scoping element is
inserted within the document

The disadvantages:

1.) a scoped style may unexpectedly apply, because an arbitrary ancestor of
the scoping element happens to partially match the scoped selector
2.) have to be very careful with using simple HTML tags in scoped selectors,
because of 1.)
3.) also because of 1.) have to be careful about recursive use of style
scopes - either programmatically generated, or in the course of XBL.

Therefore I wonder if limiting scoped selectors to only apply within their
scope wouldn't be a net benefit. IOW, in above example, the selector would
fail, because there is no element of class .foo within the parent of the
<style scope> element.

AFAICT, this change should not adversely affect the main use case for <style
scoped>, syndication. On the contrary, without disadvantage 1.) using
arbitrary outside styles within a scope should even be more robust.

Thoughts?


- Roland

Received on Tuesday, 14 June 2011 23:40:14 UTC