:deep
selector doesn't work properly with SASS nested parent selector
#12457
Replies: 4 comments
-
After a round of searching, there is really no good solution, unless you use less |
Beta Was this translation helpful? Give feedback.
-
Yes, this is a problem since third party components have callback functions that allow users to add custom CSS classes into their components but the problem is that the inserted classes lack scoping therefore they never get "selected" by the scoped CSS when using SCSS/SASS and the |
Beta Was this translation helpful? Give feedback.
-
I found a workaround but it involves using an additional class as an anchor for the Using the above example from @arrudaje: .element {
&__block {
color: #aa8855;
}
} You can add a dummy class (eg :deep(.parent) {
.element {
&__block {
color: #aa8855;
}
}
} This will produce the following CSS output .parent .element__block {
color: ##aa8855;
} Obviously, the drawback of this approach is that it introduces the need for an additional class which increases the size of the CSS generated as well as increasing the specificity of the CSS rule. To use these classes you also need to use a new parent element or use an existing parent element and add the |
Beta Was this translation helpful? Give feedback.
-
I don't think this is a vue bug. .hello {
:deep(&__subtitle) {
color: #aa8855;
}
} compiled to .hello :deep(&__subtitle) {
color: #aa8855;
} instead of :deep(.hello__subtitle) {
color: #aa8855;
} see scss playground this is difference from less, see less playground |
Beta Was this translation helpful? Give feedback.
-
Vue version
v3.2.38
Link to minimal reproduction
https://codesandbox.io/s/sad-alex-uj6q2u?file=/src/components/HelloWorld.vue
Steps to reproduce
:deep
selector:What is expected?
The style is applied correctly to the deep dynamic element
What is actually happening?
The style is not applied. This is because the
:deep
selector takes precedence to the SASS compilation phase, so the final CSS output to the browser is likeinstead of
.element__block { ... }
System Info
Any additional comments?
No response
Beta Was this translation helpful? Give feedback.
All reactions