【发布时间】:2016-05-25 03:15:30
【问题描述】:
我正在重构非响应式代码,并尝试使用 Flexbox 将以下代码显示为 2x2 网格。我曾尝试使用display: flex、flex-flow: row-wrap,但我的ul 中的图像充当块元素,不会并排放置。
这里是原始代码:
<div class="gallery">
<h2>Newest Products:</h2>
<ul>
<li><img src="http://placehold.it/360x240" alt="First gallery image" /></li>
<li><img src="http://placehold.it/360x240" alt="Second gallery image" /></li>
<li><img src="http://placehold.it/360x240" alt="Third gallery image" /></li>
<li><img src="http://placehold.it/360x240" alt="Fourth gallery image" /></li>
</ul>
</div>
.gallery {
clear: both;
}
.gallery ul {
list-style: none;
margin: 32px 0;
}
.gallery li {
float: left;
margin: 0 10px;
}
.gallery img {
width: 280px;
height: auto;
}
这个截图是我尝试使用这段代码时发生的:
.gallery {
clear: both;
display: flex;
flex-flow: row wrap;
}
.gallery ul {
list-style: none;
margin: 32px 0;
}
.gallery li {
margin: 0 10px;
flex-basis: 50%;
}
.gallery img {
width: 50%;
height: auto;
}
同样,我想要做的就是将这些图像以响应式 2x2 方向放置。谢谢!
【问题讨论】: