Subscribe on changes!

Scoped styles not being applied to child elements in render functions

avatar
Jun 1st 2023
avatar
Jun 3rd 2023

@davidleger95 According to me it is working fine.

To check this I have simplified your example Link: Simplified Version Preview: Screenshot

Note: Your style section of the component

<style scoped>
  p {
    color: blue;
  }
</style>

Gets Converted to

p[data-v-472cff63] {
    color: blue;
}

Actually rendered is something like this

Screenshot

Note: P tag does not have data-* attribute so CSS style will not get applied here.

If you want to apply some CSS to child components you need to use :deep Ref: https://vuejs.org/api/sfc-css-features.html#scoped-css

  :deep(p) {   // this way you can style child elements
    color: blue;
  }
avatar
Jun 6th 2023

Nested is a functional component. as such, its contained elements will not receive the scoped styling from its parent, except for the root element. In that regard, functional components work just like normal components: only the (single) root element will inherit scoped styles from the parent.