Scoped style and slotted elements
See original GitHub issueI have questions about <style scoped>
, <slot>
and ::slotted
pseudo-element selectors.
- Does not Vue.js support CSS scoping spec?
- If so, does Vue.js have a plan to support CSS scoping spec?
For example to explain: gist@de98f89c48e16dea2230d13925d3b3e2.
I expected a blue box to exist inside of a red box because the CSS rule slot::slotted { }
should apply to distributed elements.
But actually, a red box existed inside of another red box bacause CSS rule div { }
applied to distributed elements wrongly and slot::slotted { }
was merely ignored.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:14 (3 by maintainers)
Top Results From Across the Web
slotted() - CSS: Cascading Style Sheets - MDN Web Docs
The ::slotted() CSS pseudo-element represents any element that has been placed into a slot inside an HTML template (see Using templates and ...
Read more >Vue scoped styling not working with elements that have ...
Moving my styling to a locale setup but seeing that when I insert element into slot containers they will not work.
Read more >SFC CSS Features
When a <style> tag has the scoped attribute, its CSS will apply to elements of the current component only. This is similar to...
Read more >Styles
Styles scoped to an element's shadow tree don't affect the main document or ... Outside style targetting a slotted child can override ::slotted()...
Read more >Vue Tip: Special CSS Selectors
Slotted Selectors. By default, scoped styles do not affect contents rendered by <slot/> but we can use the :slotted pseudo-selector to apply styles...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@yyx990803 as mentioned @caikan styles will conflict if scoped parent and scoped child will have same selector in their styles and this selector will be used in slot content. I think slotted content should be affected only by scoped parent styles, except slot root.
It’s very confusing behavior.
For example we use scoped styles and this allow us to use simpler classnames. For example
.submit-button
instead ofmy-component-name__submit-button
But if I make component with
.submit-button
and slot, and then some parent will place.submit-button
in slot too,.submit-button
styles will be broken. Current behavior breaks isolation between parent-child - parent should not know about classnames of child, but for now I should check is child component have same classname or not.reproduce link
This doesn’t work for me on either named or unnamed slots content. Only the parent component id is attached to the slot.