3 ms·
I like option 3 the best, but what I'd really prefer would be block-scoped css blocks that could optionally be scoped just to children of the parent tag. I kno
by claytongulick 4y ago
I like option 3 the best, but what I'd really prefer would be block-scoped css blocks that could optionally be scoped just to children of the parent tag.
I know this is why we have shadow dom, but in practice I feel like the shadow dom has caused more problems than it solved.
Now we have a bunch of ::part things being added to make up for the problems, but it's still very difficult to work with.
I'd love to have the ability to put a <style scoped> tag inside a div and have it's rules only apply to the contents of that div, optionally overriding parent styles.
I don't know about the challenges implementing that in the engines, but it seems like it would be straightforward since the functionality already exists, style tags are valid markup almost everywhere in the dom, they're just parsed out and combined. For this you'd just have to track the parent element and bind to it like an ID selector.
This would make web component authoring more pleasant.
Edit: it looks like the functionality I'm asking for has already been considered, partially implemented, and is now deprecated, sadly.
- Sesse__ 4y agoHave you looked into @scope?
- claytongulick 4y agoI haven't! I found this [1] which basically has everything I want, but apparently it's been deprecated, which makes me sad. Searching, I found [2], is that what you're referring to? It looks like it'll do what I'm after, if a bit less gracefully. Exciting though! [1] https://css-tricks.com/saving-the-day-with-scoped-css/ https://css-tricks.com/saving-the-day-with-scoped-css/ [2] https://drafts.csswg.org/css-cascade-6/#scope-atrule https://drafts.csswg.org/css-cascade-6/#scope-atrule
- Sesse__ 4y agoYes, the latter. At least Chromium-based browsers support it behind a flag (ie., you can't use it on the web yet, but you can experiment with it and file feedback). I don't know if Firefox does, too, but they very well might.