https://css.oddbird.net/scope/explainer
https://drafts.csswg.org/css-cascade-6/#scope-atrule
Allows authors to scope style rules to a given element. The key differences between this and regular descendant combinators are:
The scope proximity cascade criterion, which makes it possible to weigh the priority of declarations according to the distance to a given scoping element.
The scoping limit, which makes it possible for a rule to apply to elements within a given subtree, but only until some specified “lower bound”.
Example:
<style>
@scope (.foo) to (.limit) {
.green { background-color: green; }
}
</style>
<div class=foo>
<div class=green>Green</div>
<div class=limit>
<div class=green>Not green (within .foo, but below .limit)</div>
</div>
</div>
<div class=green>Not green (not within .foo)</div>
Authors can also automatically scope the styles to <style>’s parent element by dropping the selector(s) in @scope’s prelude:
<div>
<style>
@scope {
.green { background-color: green; }
}
</style>
<div class=green>Green</div>
</div>
<div class=green>Not green</div>
https://github.com/w3ctag/design-reviews/issues/593
Issues addressed
Gecko: Under consideration (https://github.com/mozilla/standards-positions/issues/472)
WebKit: Positive (https://github.com/WebKit/standards-positions/issues/13)
Web developers: Positive (https://2022.stateofcss.com/en-US/usage/#missing_features_freeform)
See also emoji excitement on this post to bring back scoped styles: https://github.com/w3c/csswg-drafts/issues/3547
Other signals:
Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications? No.
The @scope rule is supported by DevTools. Style rules within @scope appear as they should, and the prelude of the enclosing @scope rule is shown similar to how rules within @media appear.
Yes
Most of the feature is covered. (wpt.fyi tests)
The failing test scope-shadow.html will be addressed before release.
The remaining WPT gaps will be closed before release. crbug.com/1450473
CSSScope
False
M117
There are no anticipated spec changes that would break compatibility. We may extend this feature with additional capabilities in the future, notably:
The :scope-end pseudo-class. https://github.com/w3c/csswg-drafts/issues/8617
Combinators (>>, ~~). https://github.com/w3c/csswg-drafts/issues/8628
Sibling scopes. https://github.com/w3c/csswg-drafts/issues/7751
The above additions would not change the behavior of what's shipping in this intent, and is just included as a preview of what might come later.
https://chromestatus.com/feature/5100672734199808
Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/O2xZZT_xCZM/m/1dPDpV-MCgAJ
This intent message was generated by Chrome Platform Status.
Contact emails
Explainer
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAKFBnUo585eMqqfxYsK65h53aT-eUCwAyYak%2BRFW40%3DtUxnMDg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/6c39ac28-3157-44a2-bd0d-5aa2c6f92823%40Spark.
I'm wondering how @scope will interact with :visited (to make sure we avoid exposing the visitedness of links as per https://dbaron.org/mozilla/visited-privacy)
are all links treated as unvisited for the purposes of @scope?
LGTM3. If we have a potential `:visited` issue, we should make sure this is shipped with a feature flag for the next few releases. The long term solution for `:visited` is to make it less brittle (a.k.a. "directed visitedness") as we're going to keep adding new combinators that invalidate the assumptions of heuristic approaches.
--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/0000000000008609c705fd8c257a%40google.com.
Hi all, I realize this is kind of late in the feedback process, but while reading the syntax examples here I found myself pretty confused by the meaning of the "to" keyword. Especially given that the tendency is to read it as the English language sentence "Scope .foo to .bar", it seems to introduce a meaning almost entirely at odds with what it's purpose is (scope the styles TO .foo, EXCLUDING .bar rather than, e.g., "Scope .foo's styles to .bar" or something similar)Reading the explainer, it sounds like the way this syntax was arrived at was pretty path dependant (building on the previous "from: x to: y" syntax) Has the CSSWG considered any other keyword for this proposal, for example maybe something like@scope (.component) excluding (.bar) {...}Again, sorry that this feedback is coming so late in the timeline, but curious whether there were any other alternatives explored here.