Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component scoped style is not applied to the upper level element #17

Closed
ivstas opened this issue Aug 17, 2015 · 6 comments
Closed

Component scoped style is not applied to the upper level element #17

ivstas opened this issue Aug 17, 2015 · 6 comments

Comments

@ivstas
Copy link

ivstas commented Aug 17, 2015

Suppose we have a component like this:

<template>
  <section>
    <p>I am content</p>
  </section>
</template>
<style scoped>
  section { background: white }
  p {color: black}
</style>

After being loaded, it results in html and css like this:

<section class="v-58ec653c">
  <p>I am content</p>
</section>
<style type="text/css">
.v-58ec653c section {
    background: white;
}
.v-58ec653c p {
    color: black
}
</style>

For obvious reasons, .v-58ec653c section is not being applied.

@yyx990803
Copy link
Member

You need to use :root to refer to the root element.

@yyx990803
Copy link
Member

Note in 3.0.0 it's changed to :scope

@isaaclyman
Copy link

@yyx990803 For posterity, can you clarify what :root and :scope do here? Are they the equivalent of :host in Angular 2 scoped styles? (referring to the component's tag itself, in a named component)

@jdstaerk
Copy link

Hey, sorry for re-opening this topic, but I'd like to know that too. I can't find anything related to :root or :scope in the docs.

@LinusBorg
Copy link
Member

...which is because this comment was made about vue-loader 3.0.0 - we are 10 major versions beyond this now. scoped styles work differently now and this whole thread does not apply anymore.

@blowsie
Copy link

blowsie commented Feb 12, 2019

I also ended up here...
How to achieve to following?

<style scoped>
:scope {
  --color: #000;
}
.link {
 color: var(--color);
}
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants