The responsive layout is incompatible with a Flexbox container
See original GitHub issueWhat version of Next.js are you using?
11.0.1
What version of Node.js are you using?
14.16.1
What browser are you using?
Chrome
What operating system are you using?
Ubuntu 20.04.2 LTS
How are you deploying your application?
yarn start
Describe the Bug
Images with the responsive layout are not displayed on the page if put inside a flexbox container.
Expected Behavior
Responsive images should be visible.
To Reproduce
- Create an app through:
npx create-next-app next-image-flexbox-bug
cd next-image-flexbox-bug
- Create a Next page with the following code:
// pages/next-image-flexbox-bug.js
import Image from 'next/image';
export default function NextImageFlexboxBug() {
return (
<div style={{display: 'flex'}}>
<Image
src="/sunset1.jpg"
alt="Sunset"
width={600}
height={450}
layout="responsive"
/>
</div>
)
}
- Run the server:
yarn dev
- Open in Chrome:
http://localhost:3000/next-image-flexbox-bug
- Nothing is displayed on the page (the white screen).
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Why flexbox not working responsive design with flex- ...
I'm using the Flexbox to do the design desktop and mobile but it not working... It is like this, as i want, using...
Read more >Backwards compatibility of flexbox - CSS - MDN Web Docs
In the following live example, I have floated two blocks and then set display: flex on the container. The items are now flex...
Read more >The responsive order conflict for keyboard focus - AlastairC
However, with flexbox and grid, the layout can be independent from that order. This is a good thing overall, and allows a lot...
Read more >4. Flexbox Examples - Flexbox in CSS [Book]
Flexbox Examples You now have a complete understanding of the CSS Flexible ... In just a few lines of CSS, we can make...
Read more >Never make your text container a flexbox container
Loosely speaking, the flex items of a flex container are boxes ... element a flexbox container, that has an explicit impact on the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks @styfle, Please find the
bug-flexbox-wrapper
branch of this example project https://github.com/kkomelin/nextjs-image-optimization-examples/tree/bug-flexbox-wrapper You may run the project withyarn dev
and then go to this example http://localhost:3000/responsive-images The related styles are global and located here https://github.com/kkomelin/nextjs-image-optimization-examples/blob/bug-flexbox-wrapper/styles/globals.css#L27This is a known issue for
layout="responsive"
.There’s a proposal to add
layout="flex-item"
to solve this use case in #18637.In the meantime, you can use a wrapper
<div style={{ width: "100%" }}>
around the image so that becomes the flex item.https://codesandbox.io/s/determined-taussig-jjn9w?file=/pages/index.js