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

SFCs with scoped CSS don't style img/source in <nuxt-picture> #320

Open
LukaHarambasic opened this issue Jun 12, 2021 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@LukaHarambasic
Copy link

LukaHarambasic commented Jun 12, 2021

Hi,
I'm currently migrating to nuxt-image and I found a small problem with scoped CSS. Not a big one, I just removed scoped and "scoped" it with a class (see here). It would be nice if I still could use scoped. I'm not even sure if that's something nuxt-image can fix. Might be linked to #288.

Steps to reproduce

<nuxt-picture
      class="image"
      :src="post.image"
      :alt="post.alt"
      sizes="xs:200px md:500px lg:1024"
/>
<style lang="sass" scoped>
  .image
    margin: 0 0 2rem 0
    width: 100%
    display: block
    source, img
      border-radius: $border-radius
      width: 100%
      min-height: 16rem
</style>

Expected result

<source> & <img> are styled when <style lang="sass" scoped> is used.

Actual result

<source> & <img> are not styled when <style lang="sass" scoped> is used.

Thanks a lot for this nice package <3

@justinmetros
Copy link

You can usually fix this in your Nuxt components <styles> directly using the deep selector.

Nuxt/Vue 2 Scss:

::v-deep img {
  /* styles here */
}

Nuxt/Vue 2 Postcss or regular css:

>>> img {
   /* styles here */
}

Vue 3:

::v-deep(img) {
  styles
}

I very rarely use sass so hopefully that works like:

::v-deep img
  /* styles */

I'm not sure exactly how scoped css is parsed, but I've run into this need in Nuxt many times. I think the concept is that the scoped css belongs only to your component, and the internal DOM that is created by <nuxt-img> in this case is another component. To style it scoped from your parent you need the deep selector.

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

No branches or pull requests

3 participants