-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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 additional next/image
layout modes
#18637
Comments
Also what about using image as a background? I would imagine some function what returns string to the image |
The problem with returning a single image URL is you'd lost many of the optimisations that In the past I've replicated CSS
This works really well and allows you to use
|
@g-elwell you can easily pass that along: <Image src="..." layout="fill" style={{ objectFit: 'cover' }} /> |
And result is:
No css is applied and some extra couple divs are added. |
@FDiskas you have to be on |
Sorry, what I meant to say was I appreciate you can pass it in, and either way I will be using that mode for background images all the time! I just figure I'd want |
<div className={styles.container}>
<Image
className={styles.background}
src="https://source.unsplash.com/2560x1440/weekly?nature"
layout="fill"
/>
</div> .container {
position: fixed;
height: 100vh;
width: 100vw;
overflow: hidden;
z-index: -1;
}
.background {
object-fit: cover;
} |
@Timer Thoughts on adding the above background image workaround to the docs? There was a request on Discord for this. |
@leerob Its in the docs on canary and updated in the examples on canary https://github.com/vercel/next.js/blob/canary/examples/image-component/pages/background.js Also see the usage for |
Is there a way for the images to have it's height based on the parent while maintaining aspect ratio? For example, the layout below: .container {
width: auto;
height: 100%;
} <div className="container>
{/* assume all forms of layout */}
<Image src="/my/image.png" />
</div> Doesn't work and does not maintain the aspect ratio of the image. (It has the height of the parent but 0 width). It broke some of the images with this kind of styling, therefore I reverted these into the native image element. |
Is there any way to use |
Yeah this latest change broke my images as well and |
same, unsized worked really well. Changing to |
same, layout fill seems to break the image |
Well it worked when I gave the stylings to it's parent div since fill is taking 100% width and 100% height |
Hi folks, I'm following up on an issue raised in #18637, #18911, and later by myself in #21914 (oops). @Timer mentioned in #18637 that this would the right place to follow up on this topic. In #18637, @Timer said the issue in question (extra whitespace being added below an image) is an expected behaviour, but that doesn't seem quite right to me. My understanding is that Thanks very much, and thanks to everyone for all your work on this component! |
It isn't a drop-in replacement for I mentioned some of this issues in this same thread (reply just above yours) We ended up reverting those changes. We still use Next.js Image default loader but without their |
I managed to fix this for myself, by adding a wrapper with the specific width and height, adding the same width and height for the image, and setting the layout to "fixed". You probably can achieve the same effect with the layout: "fill", but in my case "fill" messes up my other elements. <div
style={{ width: '326px', height: '445px' }}
>
<Image
src="/images/Profile.png"
layout="fixed"
width={326}
height={445}
/>
</div> This is a specific case where I know the exact image width and height, which of course doesn't fix the main issue here, but hope this helps other people who have the same case as me. 🙏 |
Targeting the parent div of the component (the one with |
Adding JSX: SCSS: |
Worked for me. Thanks @jonrrivera |
Is there a solution to remove the |
This PR adds a new layout mode for images called `raw`, as discussed with the core team a while back. This mode has the following characteristics: - No wrapper `span` around the `img` element - No sizer svg - Almost no styles automatically added to the `img` element - `style` parameter is allowed and is passed through to the underlying `img` element This also adds documentation changes to describe the new component. There are a few tradeoffs and DX decisions that may warrant discussion/revision before merging. I'll add a few comments to highlight those issues. - Related to #18637
We've added a new experimental |
We shipped Learn more: https://nextjs.org/blog/next-12-3 Update: Next.js 13 renamed Learn more: https://nextjs.org/blog/next-13 |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Feature request
We should add further layout modes:
fixed-height
(forceswidth: auto
?)flex-item
The text was updated successfully, but these errors were encountered: