I have designed a grid with dimensions of "3x2" using media queries. The grid appears correctly on desktop, but when viewed on mobile it changes to a "2x3" grid. However, the issue arises when there is varying text length in each grid item. To prevent items from touching the row below, I added a margin to the bottom of each "item".
Upon running the code provided below, everything seems to be working fine. The problem occurs when there are discrepancies in text lengths, causing misalignment of rows in the grid.
.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>
(Remaining HTML code for other items)
</div>
</div>
The code functions well in this layout:
https://i.sstatic.net/ZVMPA.png
However, the grid's rows become misaligned when text lengths differ:
https://i.sstatic.net/iS4k6.png
If anyone has suggestions on how to ensure all rows have the same height as the largest element within them on mobile devices (or any other solution), your input would be greatly appreciated.