首页 > 解决方案 > 取一个 div 的最大尺寸并使它们都相同

问题描述

我想从页面中获取最大的图像高度,并通过使用图像占位符或其他东西使所有图像处于相同高度,也可以响应:桌面/移动/桌子

最重要的是,我们谈论图像。我有一个高度为 600 像素的图像和另一个高度为 300 像素的图像。让我们来看看这个场景:

<div id="images">
    <img src="" alt="" width="350" height="600">
    <img src="" alt="" width="350" height="200">
    <img src="" alt="" width="350" height="350">
    <img src="" alt="" width="350" height="450">
    <img src="" alt="" width="350" height="350">
    <img src="" alt="" width="350" height="150">
    <img src="" alt="" width="350" height="350">
    <img src="" alt="" width="350" height="350">
    <img src="" alt="" width="350" height="550">
    <img src="" alt="" width="350" height="350">
</div>

在这种情况下,我想检查整个页面的最大高度,并将其作为透明背景放在所有图像上,主图像在中间。我对此无能为力,因为我不知道该怎么做,因此请在这里寻求帮助。谢谢

标签: javascriptjqueryhtmlcss

解决方案


如果您想让图像响应桌面、移动、平板电脑,您可以将宽度设置为使用65vw而不是350px.

例子:

<img src="https://en.wikipedia.org/wiki/File:Googlelogo.png" alt="" style="width:50vw">

我认为你可以用 JavaScript 做一些事情来搜索每个图像的属性以找到最大的图像高度。或者如果你自己设置它会更容易。


推荐阅读