Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  165] [ 4]  / answers: 1 / hits: 35636  / 5 Years ago, thu, august 29, 2019, 12:00:00

I have a parent component:



<template>
<ChildComponent :styles=styles />
</template>

<script>
export default {
data: () => ({
styles: `
p {
color: red
}
`
})
}
</script>


And this is the child component:



<template>
<p>Hello World</p>
</template>

<script>
export default {
props: {
styles: {
type: String,
required: true
}
}
}
</script>

<style scoped>

</style>


Now I want to use those styles provided by the parent component in child as scoped styles. Like for example:



<!-- ChildComponent.vue -->

<style scoped>
p {
color: red
}
</style>


Is there any way to do so?


More From » css

 Answers
8

If you want to target the child elements with scoped styling you have to use the deep selector.



Which can be done with



a >>> b { color : red; }
/deep/ a b { color : red; }
a::v-deep b { color : red; }


Here is the full explanation: https://vue-loader.vuejs.org/guide/scoped-css.html#child-component-root-elements


[#51718] Wednesday, August 21, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raveno

Total Points: 453
Total Questions: 92
Total Answers: 92

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
raveno questions
;