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

Add "class" attribute to Eleventy Image Picture tag #243

Open
kubarenatioN opened this issue Aug 9, 2024 · 3 comments
Open

Add "class" attribute to Eleventy Image Picture tag #243

kubarenatioN opened this issue Aug 9, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@kubarenatioN
Copy link

Is your feature request related to a problem? Please describe.

As of versions

"@11ty/eleventy": "3.0.0-alpha.17",
"@11ty/eleventy-img": "^4.0.2", 

Eleventy Image Plugin generates the following output for <img /> tag:
image

So, as we see, initial image gets wrapped by <picture> tag with sources, in case there is 2+ formats for image provided in Image Plugin config. Refs:

If there will be only one format, e.g. ['jpeg'] or ['webp'], eleventy will output initial <img> tag.

All this fine, until we start styling image with multiple formats using CSS class.
On the image attached above, we can observe class name hero__bg-image. The problem is that element with that class is wrapped by picture, so this makes it hard to style the whole image block.

For example, this css:

.hero__bg-image { width: 50% }

will make <img> box half of the size of the picture box, but not half of the container of the picture.

As was said above, such behavior makes it hard to style image by css classes.
Possible workarounds are to style by picture tag selector or using parent flexbox/grid layouts. Both options are kinda messy.

Describe the solution you'd like

I'd like to suggest adding some css class (configurable) for picture output, duplicating <img> tag class/classes but adding some prefix, for example "--picture"

Having
<img class="my-img">

with Eleventy Image Plugin transformation will output wrapping picture tag like this:

<picture class="my-img--picture"> 
 <img class="my-img">
</picture

Describe alternatives you've considered

No response

Additional context

Also, I'd like to discuss the following point – can we avoid using picture tag, and use just srcset and sizes attributes directly on the <img>?

I'm comparing it with NextJS, and they just use with huge srcset attr.
Correct me if I'm wrong, but we can specify different image formats in srcset tag.

@kubarenatioN kubarenatioN added the enhancement New feature or request label Aug 9, 2024
@tarunsinghofficial
Copy link

Hi @kubarenatioN, Can I please work on this? If, yes please assign me this issue.

Thanks!

@kubarenatioN
Copy link
Author

kubarenatioN commented Aug 10, 2024

Hi, @tarunsinghofficial. Of course you can!
Unfortunately, I cannot assign the issue to anyone. May be @zachleat can assist on this...

@zachleat zachleat transferred this issue from 11ty/eleventy Sep 3, 2024
@hottabov
Copy link

Hi guys! Any news about this issue?

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