有没有办法使NextJS映像组件填充其父容器的宽度并以高度响应以保持其尺寸?

发布于 2025-02-10 00:09:51 字数 570 浏览 2 评论 0原文

我想并排有两个JS图像组件,并在屏幕宽度上填充(当然有一点填充),但具有响应高度以保持图像的尺寸。

这是我的代码:

<div className='flex flex-row p-4 border w-full justify-center'>

            <div className='w-1/2 h-screen border relative'>
                <Image src="{src}" layout='fill' />
            </div>

            <div className='w-1/2 h-screen border relative'>
                <Image src="{src}" layout='fill' />
            </div>
 </div>

显然,指定父div上的宽度和高度并填写图像不会保留其尺寸,因此我的本能是使用H-Max来设置宽度并填充图像高度,但是在屏幕上它是空的,因为没有什么可填充...

I would like to have two Next JS image components side-by-side and fill the screen width-wise (with a bit of padding, of course) but have a responsive height to preserve the images' dimensions.

Here is my code:

<div className='flex flex-row p-4 border w-full justify-center'>

            <div className='w-1/2 h-screen border relative'>
                <Image src="{src}" layout='fill' />
            </div>

            <div className='w-1/2 h-screen border relative'>
                <Image src="{src}" layout='fill' />
            </div>
 </div>

Obviously, specifying a width and height on the parent div and fill on the image will not preserve its dimensions, so my instinct was to use h-max instead to set a width and have it fill the image height, but on screen it is empty since there is nothing to fill...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一城柳絮吹成雪 2025-02-17 00:09:51

您可以使用的一件事/骇客是用&gt;div 将类添加到此div(例如h)或w),并将图像响应式IE 布局的布局=响应。这将使图像随着尺寸的变化而波动。

One of the things/hacks you can use is to wrap the <Image> with a div and add classes to this div (like h or w) and put the layout of the image responsive i.e.layout=responsive. This will allow the images to be volatile with changing dimensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文