简体   繁体   English

以div的最大尺寸并使其全部相同

[英]Take the biggest size of a div and make all of them the same

I would like to take the biggest image height from the page and make all the images at same height by using images placeholders or something, also to be responsive: desktop / mobile / table 我想从页面上获取最大图像高度,并通过使用图像占位符或其他方式使所有图像都处于同一高度,以便响应:台式机/移动设备/桌子

Most important, we speak about images. 最重要的是,我们谈论图像。 I have an image with 600px height and another one with 300px height. 我有一幅高度为600px的图像,另一幅高度为300px。 Lets take this scenario: 让我们来看看这种情况:

<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>

In this scenario, I want to check entire page for the biggest height and put it on all images as a transparent background with the main image in the middle. 在这种情况下,我想检查整个页面的最大高度,并将其作为透明背景放在所有图像上,并将主图像放在中间。 I don't have nothing did on this because I don't know what to do and I kindly ask for help here. 我对此没有做任何事情,因为我不知道该怎么办,请在这里寻求帮助。 Thanks 谢谢

If you want to make the images responsive for Desktop, Mobile, Tablet, you could set the width to use 65vw instead of 350px . 如果要使图像响应于台式机,移动设备和平板电脑,则可以将宽度设置为使用65vw而不是350px

Example: 例:

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

I think you could do something with JavaScript to search through each image's properties to find the biggest image height.. Or if you set it yourself that would be easier. 我认为您可以使用JavaScript进行某些操作,以搜索每个图像的属性以找到最大图像高度。或者,如果您自己进行设置,那会更容易。

Use background images and a nested div to set the aspect ratio. 使用背景图像和嵌套的div来设置纵横比。

 #images .image { width: 350px; max-width: calc(50% - 5px); float: left; margin: 0 5px 5px 0; display: inline-block; background-color: black; background-position: center center; background-size: contain; background-repeat: no-repeat; } #images .image div {padding-top: 100%;} 
 <div id="images"> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat2.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat2.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat2.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat2.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat.jpg);"><div></div></div> <div class="image" style="background-image: url(https://jekyllcodex.org/uploads/grumpycat2.jpg);"><div></div></div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM