【发布时间】:2022-02-10 13:05:29
【问题描述】:
我正在尝试使用 flexbox 为我的网站创建一个响应式图片库。但是,我试图让它换行到下一行并保持秩序,我遇到了麻烦。例如:
桌面
1,2,3
4,5,6等
平板电脑
1,2
3,4等
手机
1
2等
请查看我包含的示例代码。
.row {
display: flex;
flex-wrap: wrap;
}
.column {
flex: 33%;
max-width: 33%;
}
.column img {
vertical-align: middle;
width: 100%;
}
@media screen and (max-width: 800px) {
.column {
flex: 50%;
max-width: 50%;
}
}
@media screen and (max-width: 600px) {
.column {
flex: 100%;
max-width: 100%;
}
}
<div class="row">
<div class="column">
<figure>
<img src="https://img.webnots.com/2014/04/112.png">
<figcaption>Caption 1</figcaption>
</figure>
<figure>
<img src="https://img.webnots.com/2014/04/42.png">
<figcaption>Caption 4</figcaption>
</figure>
</div>
<div class="column">
<figure>
<img src="https://img.webnots.com/2014/04/22.png">
<figcaption>Caption 2</figcaption>
</figure>
<figure>
<img src="https://img.webnots.com/2014/04/52.png">
<figcaption>Caption 5</figcaption>
</figure>
</div>
<div class="column">
<figure>
<img src="https://img.webnots.com/2014/04/32.png">
<figcaption>Caption 3</figcaption>
</figure>
<figure>
<img src="https://img.webnots.com/2014/04/62.png">
<figcaption>Caption 6</figcaption>
</figure>
</div>
</div>
【问题讨论】:
标签: html css flexbox media-queries