I've been struggling to work with NextJS's Image
component.
My goal is to set up a banner image that only covers a specific amount of space on the screen, regardless of screen size. I have managed to achieve this by using max-height: 30vh
and overflow: hidden
. However, I'm facing an issue with centering the image as the screen size changes. The focus should shift from viewing the entire image to focusing on the bed, but instead, it seems to be centered on the ceiling of the picture.
Check out a live sample: https://codesandbox.io/s/nextjs-image-layout-lc7vb?file=/src/pages/index.tsx
const Index = (props: IBlogGalleryProps) => (
<Main
...
>
<div className="w-full overflow-hidden" style={{ maxHeight: '30vh' }}>
<Image width="300" height="200" layout="responsive" src="https://images.unsplash.com/photo-1519494080410-f9aa76cb4283?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1920&q=80" />
</div>
...
</Main>
);