CSS class on <nuxt-picture> is appended to <picture> and not <img>
See original GitHub issueCSS 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:
- Created 2 years ago
- Reactions:9
- Comments:7 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@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-classprop 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.@LukaHarambasic Yeah it would be a work around for #320. However, you can also use a deep selector to solve your issue: