3 ms·
How is Svelte solving these problems in Vue Components? > 2. A child component's root node will be affected by both the parent's scoped CSS and the child's sco
by Kiro 9y ago
How is Svelte solving these problems in Vue Components?
> 2. A child component's root node will be affected by both the parent's scoped CSS and the child's scoped CSS.
> 5. Be careful with descendant selectors in recursive components! For a CSS rule with the selector .a .b, if the element that matches .a contains a recursive child component, then all .b in that child component will be matched by the rule.
https://github.com/vuejs/vue-loader/blob/master/docs/en/features/scoped-css.md https://github.com/vuejs/vue-loader/blob/master/docs/en/feat...
If it's the same in Svelte I don't see how scoped CSS solves anything. I still need to be careful not to let the CSS bleed into the child components.
- rich_harris 9y agoIt's not the same. Styles declared in a Svelte <style> block only pertain to that component, unless you opt-in to the cascade with a little bit of extra syntax borrowed from CSS modules: `:global(.foo) {...}`. You can also compile Svelte components to custom elements, which use shadow DOM to enforce complete style isolation (though this is a new and experimental option).
- spankalee 9y agoShadow DOM is the real answer here.
- madeofpalk 9y ago> I still need to be careful not to let the CSS bleed into the child components. In practice, this means not to use selectors like .a * which is pretty easy to avoid (and you probably should be anyway)