Scoped styles don't apply to v-html injections
See original GitHub issueVersion
11.0.0
Reproduction link
https://github.com/foundryspatial-duncan/vue-loader-issue-demo/blob/master/src/App.vue
Steps to reproduce
- In a single-file Vue component (.vue file), add some scoped styles (with the
scoped
property on thestyle
tag). - Inject some HTML that matches your scoped style’s selector with v-html
What is expected?
The styles would affect the injected HTML
What is actually happening?
The styles do not affect the injected HTML
Looks like HTML injected with v-html aren’t given the “data-v-[hash]” property (like data-v-08ce5946). I think there’s a proposal somewhere to only add the data-v-[hash] to the component’s root element and then prefix all the styles to scope them. That would solve this issue as well.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:20 (1 by maintainers)
Top Results From Across the Web
Scoped styles with v-html - Medium
Scoped styles with v-html ... Scoped css is awesome and I strongly encourage its use when building reusable components. It stops the css...
Read more >Applying global CSS to injected HTML (v-html) - Stack Overflow
In single-file components, scoped styles will not apply to content inside v-html, because that HTML is not processed by Vue's template ...
Read more >Styling Vue Single-File Components - This Dot Labs
Scoped styles allows us to write CSS that only applies to the component we are working in. Here's an example from the Vue...
Read more >Built-in Directives - Vue.js
In Single-File Components, scoped styles will not apply to content inside v-html , because that HTML is not processed by Vue's template compiler....
Read more >Understanding Vue's Deep CSS Selector - Telerik
We're going to make them loop with a v-for and render three of them per parent, ... Scoped styles apply only to this...
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
You can use the
/deep/
selector to get your styles to be applied:I stumbled upon this today and oddly, nothing was working (unscoped css, global css).
I noticed that while this solution worked, the
/deep/
selector was deprecated by some time ago and throws errors in IE: https://stackoverflow.com/questions/25609678/what-do-deep-and-shadow-mean-in-a-css-selectorI then found this: https://medium.com/@brockreece/scoped-styles-with-v-html-c0f6d2dc5d8e
Which recommends something along the lines of:
Which works as well, without a deprecated selector.
edit: Then again, the vue docs say
>>>
is just an alias for/deep/
, so I’m not sure anymore https://vue-loader.vuejs.org/guide/scoped-css.html#deep-selectors