I've created a 3x2
grid using media queries. It displays fine in its default view, on a desktop. When on mobile it becomes a 2x3
grid but there's a problem when there's a different amount of text in each one. I've added a margin to the bottom of item
so that they don't touch the row below.
If you run the code below, all seems to be fine. My issue is when there's different lengths of text, the grid is broken and each row isn't aligned correctly.
.wrap {
width: 80%;
margin-left: auto;
margin-right: auto;
}
@media only screen and (max-width: 500px) {
.wrap {
width: 90%;
margin-left: auto;
nargin-right: auto;
}
}
.container {
display: table;
width: 100%;
}
.item {
width: 33.3%;
float: left;
margin-bottom: 10px;
}
@media only screen and (max-width: 500px) {
.item {
width: 50%;
float: left;
margin-bottom: 15px;
}
}
.item-info {
max-width: 90%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.item-icon{
width: 50px;
height: 50px;
background: url(https://via.placeholder.com/50x50) bottom no-repeat;
background-size: contain;
margin-left: auto;
margin-right: auto;
<div class="wrap">
<div class="container">
<div class="item">
<div class="item-icon"></div>
<div class="item-info">
<h1>Title</h1>
<p>A short paragraph goes here</p>
</div>
</div>
<div class="item">
<div class="item-icon"></div>
<div class="item-info">
<h1>Title</h1>
<p>A short paragraph goes here</p>
</div>
</div>
<div class="item">
<div class="item-icon"></div>
<div class="item-info">
<h1>Title</h1>
<p>A short paragraph goes here</p>
</div>
</div>
<div class="item">
<div class="item-icon"></div>
<div class="item-info">
<h1>Title</h1>
<p>A short paragraph goes here</p>
</div>
</div>
<div class="item">
<div class="item-icon"></div>
<div class="item-info">
<h1>Title</h1>
<p>A short paragraph goes here</p>
</div>
</div>
<div class="item">
<div class="item-icon"></div>
<div class="item-info">
<h1>Title</h1>
<p>A short paragraph goes here</p>
</div>
</div>
</div>
</div>
Running the code is fine when it looks like this:
But the rows aren't even when there's different text lengths;
Any ideas on how to make all of these rows the same height as the largest one in each row on mobile (or another fix) would be appreciated.