我正在尝试在两行中获得多个图像。但是,它最多可以正确对齐9张图像。但是,在9张图像之后,下一张图像显示在第三行中。我想将其保持在2行。我该如何实现? D: 我正在尝试使其看起来像zillow.com和hotels.com等网站的图库部分,其中用户发布其图像并将其上传。并非所有人都会拥有那么多图像,但以防万一。我不希望有一个最大。
.grid-container {
display: grid;
grid-template-columns: repeat(5, 1fr);
grid-auto-rows: 165px;
grid-gap: 10px;
}
.grid-container>div {
text-align: center;
font-size: 30px;
}
.item1 {
grid-row: 1 / 3;
}
.detailed-gallery-outer {
overflow: hidden;
width: 100%;
}
.detailed-gallery-inner {
float: left;
position: relative;
}
.detailed-gallery-tmb {
float: left;
margin: 0 10px 0 0;
}
.detailed-gallery {
display: flex;
justify-content: space-between;
padding: 0;
position: relative;
width: 1140px;
margin: 0 auto;
}
<div class="detailed-gallery">
<div class="arrow-left">
<div class="arrow-left-small">
</div>
</div>
<div class="container">
<div class="detailed-gallery-outer">
<div class="detailed-gallery-inner">
<div class="grid-container">
<div class="item1"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office1" width="250" height="340" /></div>
<div class="item2"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office2" width="250" height="165" /></div>
<div class="item3"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office3" width="250" height="165" /></div>
<div class="item4"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office4" width="250" height="165" /></div>
<div class="item5"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office5" width="250" height="165" /></div>
<div class="item6"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office6" width="250" height="165" /></div>
<div class="item7"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office7" width="250" height="165" /></div>
<div class="item8"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office8" width="250" height="165" /></div>
<div class="item9"><img src="https://www.w3schools.com/howto/img_forest.jpg" alt="office9" width="250" height="165" /></div>
</div>
</div>
</div>
</div>
<div class="arrow-right">
<div class="arrow-right-small">
</div>
</div>
</div>
我也可以发布JS代码,但是我认为这不是问题。
答案 0 :(得分:0)
只需删除grid-row: 1/ 3;
从
.item1 {
grid-row: 1 / 3;
}
TO
.item1 {
grid-row: 1 / 2;
}
此外,您必须调整容器的宽度。要么设为100%
,要么更改为大于5x250=1250
的。
检查this P.S.我添加了1张相同的9图片。