-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Image warning issue - If you use CSS to change the size of your image, also include the styles 'width: "auto" or 'height: "auto"' to maintain the aspect ratio #56025
Comments
Just add this, depending on what you need
or |
Having auto width and height doesn’t make sense. It’s one or the other. What’re you trying to achieve by setting both properties to auto? |
I'd like to use tailwind to keep consistent |
I wnat max-h-[32] and w-full I mean image should be max-h-[32px] If I set max-h-[32px] and in atributes width={300} my image has 300px width - I don't want it |
This comment has been minimized.
This comment has been minimized.
This issue still open - somebody know how to fix this? |
I'm still see this issue
|
I'm running into this issue as well.
With this:
And still have the issue with this:
|
@CitizenBeta It is strange you have the |
UpdateHey I updated MVP |
Removing that solved it for me. I honestly don't know how that got there, maybe it was in a code sample. Thank you! |
This comment has been minimized.
This comment has been minimized.
Yeah this is still an issue. I set both properties, follow the directions, and still randomly get this warning. |
Hello. @tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
img {
width: auto;
height: auto;
}
} If you are not using tailwindcss, it would be good to check if there is a css file that modifies width, height of img tag with the same principle. |
After suggested fix: (console has been cleared and page has been refreshed) MVP - https://codesandbox.io/p/devbox/mvp-warn-img-aspect-ratio-md683h @Jungho-Cheon - please provide mvp where fix work for you |
Work for me, thanks! |
Provide mvp please |
Can confirm this warning is unfixable. It is a bug. |
|
I need max width that fit original aspect ratio |
I keep seeing comments suggesting fixes and possible solution, can we all agree that:
|
Same with next.js Image warning here |
I was able to fix the error with the globals.css option: But after that i got a new error: The resource was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate Never had this issue before with NextJS must be some sore of bug. |
To solve this problem, I used the tip to add @layer base { img { width: auto; height: auto; } } in globals.css, and for every image, I wrapped it in a div and applied all the CSS options to that div. |
Please add a little bit of code that demomstrated how NOT to do and and HOW to do |
I have the same problem, using Tailwind. No amount of extra |
The only thing that worked for me is to actually set a style like so: <Image
alt={productName}
width={114}
height={91}
style={{ width: '114px', height: '91px' }}
src={image}
/> the tailwind |
for me was
|
dont change or add any @layer to tailwind global css, just add a div as parent of next/image and add the height and weight values on this div, like i showed above
|
I'd like to argue that this warning shouldn't show up if there's an |
w-auto h-auto aspect-auto max-h-[369.78px] max-w-[208px] min-w-[208px] min-h-[369.78px] |
Work for me, thanks! this is my setting @layer base {
img {
max-width: 100%;
height: auto;
width: auto;
aspect-ratio: auto;
}
} NOTE : |
priority and style={{ width: |
Tell me more about where you get this size from? |
only with this can get rid of the warning when using tailwindcss |
As suggested by @xzedx, in my case it works by adding <Image
src="......"
alt="......"
width={308}
height={384}
className="h-full w-auto max-w-none object-cover"
/> |
This works for me using Tailwind (I need figure tag to wrap image)
Le edit: You can use this, too:
Le second edit: Based on this answer, you can try this:
Yes, I can use another AspectRatio from certain component libraries, because I'm using a 16:9 picture, but my component is in the another way (Excuse my english) |
This worked for me but this affected size of the other images on my site. When I tried inline style |
Link to the code that reproduces this issue
demo - https://ominous-space-broccoli-9qgwx9pqq6p2pxvq-3000.app.github.dev/
mvp - https://ominous-space-broccoli-9qgwx9pqq6p2pxvq.github.dev/
mvp codesandbox - https://codesandbox.io/p/devbox/mvp-warn-img-aspect-ratio-md683h
github - https://github.com/nicitaacom/acc2-image-warning-to-maintain-the-aspect-ratio
To Reproduce
See this
I already use width auto and height auto
Current vs. Expected behavior
I don't want to see useless warnings in my console
Now I see useless warning that impossible to fix (I tried add some tailwind classes - issue persists)
Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Binaries: Node: 16.17.0 npm: 8.15.0 Yarn: 1.22.19 pnpm: 7.1.0 Relevant Packages: next: 13.5.1 eslint-config-next: 13.5.1 react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Image optimization (next/image, next/legacy/image)
Additional context
I tried it with next 13.5.3 - the same result
For search engines
Image with src "/success-checkmark.gif" has either width or height modified, but not the other. If you use CSS to change the size of your image, also include the styles 'width: "auto"' or 'height: "auto"' to maintain the aspect ratio.
The text was updated successfully, but these errors were encountered: