Replies: 1 comment 3 replies
-
If fill is used, it takes up the entire size of the parent tag, but the width of the "ImageWrapper" is 100%, which may differ from the original width of the image, and the height seems to be set to zero and is not visible. import Image from 'next/image';
export default function ImageWrapper({ src, alt }) {
return (
<div style={{ width: '600px', height: '400px', position: 'relative' }}>
<Image src={src} alt={alt} fill quality={100} />
</div>
);
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I want to basically have an image of which the width, height and aspect ratio are unknown, to fit a parent container completely and keep it's aspect ratio. I couldn't find any documentation that helped me solve this problem.
Below you can see a simple wrapper Component that would be reusable and of which I thought would work. I hope it's even possible at this point.
I know there is the trick of doing some padding for the top but this has the same effect as just setting a height on the div and setting the objectPosition to be bottom. The height/paddingTop would need to match the images height exactly and if I know the height to begin with I didn't have this problem.
Setting the height on the div to auto or 100% doesn't work either.
Additional information
Example
https://stackblitz.com/edit/nextjs-emz9yh?file=app%2Fpage.jsx
Beta Was this translation helpful? Give feedback.
All reactions