【发布时间】:2021-06-01 06:29:28
【问题描述】:
我正在尝试使用 Django 和 python 创建一个图片库。我是 HTML 和 CSS 的新手,需要在网格中显示图像。我希望一行中的一个图像具有相同的高度但不同的宽度,例如Deviantart's。并且列数应该不同,如下图所示。
我可以像这样在画廊中显示图像。
但图像的高度不同且顺序不正确。有没有办法实现像第一张图片一样的画廊?
感谢您的宝贵时间!
更新:这是我目前正在使用的代码。
.gallery-container {
column-count: 4;
column-gap: 5px;
margin: 20px;
}
.gallery-item {
display: inline-block;
width: 100%;
background: #1e1f26;
border-radius: 6px;
}
.gallery-item img {
display: block;
border-radius: 5px;
width: 100%;
}
<div class="gallery-container">
<div class="gallery-item">
<img src="https://images.unsplash.com/photo-1485550409059-9afb054cada4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=401&q=80" alt="">
</div>
<div class="gallery-item">
<img src="https://images.unsplash.com/photo-1493612276216-ee3925520721?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=400&q=80" alt="">
</div>
<div class="gallery-item">
<img src="https://images.unsplash.com/photo-1499854413229-6d1c92ff39ef?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=802&q=80" alt="">
</div>
<div class="gallery-item">
<img src="https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=751&q=80" alt="">
</div>
<div class="gallery-item">
<img src="https://images.unsplash.com/photo-1500462918059-b1a0cb512f1d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=334&q=80" alt="">
</div>
<div class="gallery-item">
<img src="https://images.unsplash.com/photo-1496449903678-68ddcb189a24?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80" alt="">
</div>
</div>
【问题讨论】:
-
能否将您的 HTML 和 CSS 包含在您尝试过的内容中?
-
@TannerDolby 我更新了问题,我应该早点包含代码。
标签: html css image-gallery