question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS class on <nuxt-picture> is appended to <picture> and not <img>

See original GitHub issue

CSS classes on <nuxt-picture> goes to HTML element <picture>, however, it should go to <img> element. Current solution pretty much blocks devs from using utility classes/frameworks.

Example

Code

<nuxt-picture
	:src="post.featured_media"
	width="600"
	height="300"
	class="w-100 br-8"
/>

Actual result

<picture class="w-100 br-8">
	<source type="image/webp" srcset="...">
	<img src="....">
</picture>

Expected result

<picture>
	<source type="image/webp" srcset="...">
	<img src="...." class="w-100 br-8">
</picture>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
dannyalder88commented, Jun 14, 2021

@LukaHarambasic I think the img tag inside a picture tag is always used to render the image and so its class list would apply no matter which source is used. But you are right, there may be times when you would want to target the picture container with a class as well.

@lucien144 Maybe an img-class prop might help in this case to apply classes directly to the img tag? Otherwise, you could target it in the CSS with .picture-class img {}. This could get annoying for CSS frameworks using utility classes though.

4reactions
dannyalder88commented, Jun 14, 2021

@LukaHarambasic Yeah it would be a work around for #320. However, you can also use a deep selector to solve your issue:

<nuxt-picture class="image" ... />

<style lang="sass" scoped>
    .image
        // Styles for picture tag
        ::v-deep img 
            // Styles for img tag
</style>
Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS class not applying correctly to image on site
I'm trying to split my page into 2 divs, each taking 50%. The left contains an image, whereas the right contains text. This...
Read more >
Forums - CSS - Need help applying a class to an image
I've changed to a new CMS system which, like many others, allows images to be added to a page. There is a class...
Read more >
Picture perfect image optimization for any web framework
Image optimization is never fun to deal with. Let's learn how the picture element + 11ty can save any static site from bloated...
Read more >
nuxt-img
Discover how to use and configure the nuxt-img component. ... Uses built-in provider to optimize local and remote images; Converts src to provider...
Read more >
SEO and Performance Optimisation with Nuxt Image
The API of the nuxt-picture component is almost identical to nuxt-img , so we don't have to add any additional props. Nuxt Picture....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found