javascript - 取一个 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>
在这种情况下,我想检查整个页面的最大高度,并将其作为透明背景放在所有图像上,主图像在中间。我对此无能为力,因为我不知道该怎么做,因此请在这里寻求帮助。谢谢
解决方案
如果您想让图像响应桌面、移动、平板电脑,您可以将宽度设置为使用65vw
而不是350px
.
例子:
<img src="https://en.wikipedia.org/wiki/File:Googlelogo.png" alt="" style="width:50vw">
我认为你可以用 JavaScript 做一些事情来搜索每个图像的属性以找到最大的图像高度。或者如果你自己设置它会更容易。
推荐阅读
- reactjs - 在 next.js react app 中设置运行时参数
- logging - TFS 构建步骤 - 遇到错误 TF400893:无法联系服务器。请检查您的网络连接,然后重试
- html - Flip Boxes 不能在 Mac 上运行,但可以在手机上运行
- c# - 在测试控制器发布方法时,我如何模拟 MySql 数据库返回的主键
- c - 在 STM32f103 上的 PWM 定时器比较匹配时无法获得中断
- javascript - javascript按钮事件剂量正常工作
- google-sheets - 数组公式以及如何使用 COUNTIF 和 IF 语句对其进行格式化
- java - 如何知道这个 while 循环是 O(n) 还是 O(1)?
- c++ - 包含同一类成员的类
- c# - SSMS 的 VSIX 扩展 - 如何将菜单项添加到结果网格中的上下文菜单?