-
Notifications
You must be signed in to change notification settings - Fork 679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[css-cascade-6] A way for <style> elements to scope to their parent element #6606
Comments
If I understand this right, the new feature required for this is a
I don't see any particular reason it should be restricted to use in |
As is typical for spec bugs, I think I've got two ideas piled into one:
If |
Right. But I think one of the issues with I like the pseudo-class idea because it avoids that issue, while building on top of the more flexible CSS-selector driven approach to |
Couldn't authors just use a polyfill (i.e. https://github.com/samthor/scoped)? |
Going a bit off-topic (feel free to hide the comment as such): People are wanting to scope IDREFs in HTML: https://discourse.wicg.io/t/relative-element-references-in-html/5627/, someone suggested a |
Regarding the backwards compatibility issue, would it be possible to define a CSS selector that refers to the current location of a style tag? If the browser does not recognize it, the CSS selector would match nothing, rather than everything. That way we could have:
|
Regarding the issue of not wanting CSS to apply to all child elements, or "toroidal css", is that not a separate issue from local scoping? It feels as if it should be possible to define selectors indicating "style this element but not its children" (non-inherited styles) or "style this element like its parent" (explicit inheritance of normally non-inherited styles) but that trying to combine inheritance constraints with local scoping makes things complicated. |
@bitdivine The current scope proposal (and this thread) do not have any impact on inheritance. The donut scope applies to selector targeting only. I do like the approach of a syntax for pointing to style location, whatever form that might take. @Malvoz The problem is not for authors that want to use the new feature, but for legacy sites that already have nested style tags which apply globally. Authors can recreate a scoped attr using a polyfill, but any browser support for that would break legacy styles, and that's not an option. There's no way to polyfill opting-out all legacy sites from a new feature. |
I think this should be resolved by a combination of:
The first one there allows scoped imports using <div>
<style>
/* scoped to the div, since no scope root selector is given */
@scope { p { color: red; } }
</style>
<p>red</p>
</div> Closing this issue as accepted by those resolutions. If we want to work on an additional |
@andruud As far as I know, this is not currently implemented in Chrome, can you implement the new behavior in Chrome?
<div>
<style>
@scope {
p { color: red; }
}
</style>
<p>this is red</p>
</div>
<p>not red</p> That would be equivalent to: <div id="foo">
<style>
@scope (#foo) {
p { color: red; }
}
</style>
<p>this is red</p>
</div>
<p>not red</p> |
@yisibl Right, yes, the current Chrome prototype predates the resolution add that kind of scoping. It will be added eventually. I filed crbug.com/1379844 if you want to follow that for updates. |
@andruud Thanks! I am very much looking forward to the implementation of this feature. |
* [css-cascade-6] Add implicit scopes Resolves #6606. * Allow lower bounds when root is implicit --------- Co-authored-by: Miriam Suzanne <miriam@oddbird.net>
https://drafts.csswg.org/css-cascade-6/#scoped-styles
The explainer references this issue: Please bring back scoped styles.
Either there's something missing from the spec or I'm missing it, which is a way to have a
<style>
element that gets scoped to its own parent element.<style scoped>
would guarantee that the color only applied to children of the parent div.I could do it by adding a unique ID or attribute:
… this is basically what Vue does at build time. But I want the same effect without a build step!
I think we'd want something like
@scope(:style-parent)
.Otherwise, even with
@scope
back in play, I'd still have to use a build tool (or something) to generate an ID for the upper bound of the scope.The text was updated successfully, but these errors were encountered: