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.

Image component isn't fluid

See original GitHub issue

Bug report

Describe the bug

The Image component wrapper has a fixed width and can’t be changed.

To Reproduce

I created a codesandbox to illustrate the issue. https://codesandbox.io/s/image-component-isnt-fluid-vsho0

This is a really common layout, images in columns. They have a final width but they should still be fluid. If I remove the width and height props then the Image component will use the deviceSizes setting which is not ideal as those are generic.

Expected behavior

I was wondering if we could turn that fixed size off as the padding on the internal wrapper already takes care of maintaining the image ratio.

Additional context

I understand why that is there, it helps mitigate layout shifting, and I appreciate that but it’s really rare when an image is fixed, 100% of the time. The web has passed that point long ago. I also wanna start a conversation. Should the Image component use the sizes attribute and respect media queries? Using this codesandbox as an example, these images should probably be served as the following sizes="(max-width: 768px) 768px, 269px". We want a bigger image that will be 100% of the viewport and then go back to their max size.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:34
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

13reactions
marlonmarcellocommented, Oct 28, 2020

Also, maintaining just an img tag will make sure that object-fit and other css properties are respected and work as you intended.

3reactions
dkodeitcommented, Oct 28, 2020

As mentioned, If say the component width is set to 900, an inline style will be set on the image wrapper to max-width:100% width: 900px. To address this I can target the wrapper and set width:100% !important but it would be nice to have the component default to fluid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

bootstrap 4 img-fluid does not change image height
Try wrapping your image in a figure element. ... Per default, the .img-fluid class applies max-width: 100%; and height: auto; to the image: ......
Read more >
Component | Fluid Image
Fluid Image is a simple, responsive image for when the page does not know the image's aspect ratio. It will grow to fit...
Read more >
Responsive fix for the Next.js Image component
There is an easy fix to this problem, you only have to set a wrapper around the Image component to give a bit...
Read more >
Fluid Images in a Variable Proportion Layout - CSS-Tricks
The image resizes to maintain its aspect ratio without cutting off any details, and if the image is important content and should not...
Read more >
Gatsby Image API
Please check out how to work with the new gatsby-plugin-image Part of what makes… ... Fixed images; Fluid images; About noBase64; About withWebp ......
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