I am refactoring non-responsive code and am trying to display the below code as a 2x2 grid using Flexbox. I have tried using display: flex
, flex-flow: row-wrap
, but the images in my ul
are acting as block elements and won't sit side by side.
Here is the original code:
<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;
}
This screenshot is what happened when I tried using this code:
.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;
}
Again, all I want to do is place these images in a responsive 2x2 orientation. Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…