gpt4 book ai didi

javascript - 动态调整 n 个图像的行大小,所有 5 行高度一致

转载 作者:行者123 更新时间:2023-11-28 06:34:04 26 4
gpt4 key购买 nike

我有五行,容器中的图像放置在每行的容器内。

现在,我一直在寻找的是

  1. 所有 5 行的高度必须相同,无论其中的图像容器数量如何。
  2. 例如,第一行有 5 个图像容器,第二行有 3 个,第三行分别有 6 个图像容器,但它们仍应具有相同的高度,在任何分辨率下
  3. 这里的一行可以包含任意数量的图像(不同的高度和宽度),但它们应该位于图像容器中,并且图像与顶部对齐,而不是居中,以帮助缓解锯齿状。
  4. 所有图像都有不同的宽度和高度,因此在放置在图像容器中时,它们的长宽比保持不变。
  5. 的宽度取决于其中图像容器的数量,例如第一行中的 20 个图像容器的长度应比第二行中的 10 个图像容器的长度宽。

html代码

<body>
<div>new</div>
<div class="outer-wrap-img">
<div class="inner-wrap-img">
<div class="red">
<!--<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

</div>


<!--2nd row-->
<div>old</div>
<div class="outer-wrap-img">
<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>
<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

</div>
<!--3rd-->
<div>mid-level</div>
<div class="outer-wrap-img">
<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>


<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>
<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>
</div>
<!-- 4th-->
<div>older</div>
<div class="outer-wrap-img">
<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>
<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>
<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>
</div>
<!-- 5th-->
<div>oldest</div>
<div class="outer-wrap-img">
<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red">
<!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>
<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="red"><!--<img src="http://www.gettyimages.ca/gi-resources/images/Homepage/Category-Creative/UK/UK_Creative_462809583.jpg" />-->
</div>
</div>

<div class="inner-wrap-img">
<div class="green">
<!--<img src="http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg" />-->
</div>
</div>

</div>

CSS

.outer-wrap-img {
display: table;
table-layout: fixed;
width: 100%;
}
.inner-wrap-img {
display: table-cell;
padding: 2px;
}
.inner-wrap-img div {
padding-bottom: 75%;
position: relative;
}
.inner-wrap-img div img {
display: block;
max-width: 100%;
max-height: 100%;
position: absolute;
}
.red {
/* background: #F00;*/
background-color:#CCC
}
.green {
/*background: #0f0;*/
background-color:#CCC
}

Fiddle sample

最佳答案

由于您没有提供任何 Javascript,我将为您编写一些伪代码

function doResize(){
//for each parent div
resize(parent div, images in div);
}

function resize(parent, images){
var imageHeight = parentheight / image number;
//adjust images to imageheight
}

关于javascript - 动态调整 n 个图像的行大小,所有 5 行高度一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34439190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com