Could anyone offer guidance on how to properly align text underneath responsive images within divs?
The issue I'm facing is that the divs adjust smoothly based on the viewport size, but the text below them doesn't stay centered as intended.
While "text-align: center;" works fine at maximum viewport width, it gets skewed when the boxes respond to a smaller window size.
I would greatly appreciate any suggestions or tips, as I am unsure if my code snippet will be effective...
.flexgrid {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
.flexgrid > li {
width: 20%;
list-style-type: none;
}
@media only screen and (max-width: 1337px) {
.flexgrid > li {
width: 25%;
}
}
@media only screen and (max-width: 1072) {
.flexgrid > li {
width: 35%;
}
}
<ul class="flexgrid">
<li><div class="col-lg-2 col-sm-6"><img src="https://dummyimage.com/300x300/000/fff" alt="" style="display: block; height: 250px; width: 250px; margin: 5px;"></div>Coal</li>
<li><div class="col-lg-2 col-sm-6"><img src="https://dummyimage.com/300x300/000/fff" alt="" style="display: block; height: 250px; width: 250px; margin: 5px;"></div>Dry Wood</li>
<li><div class="col-lg-2 col-sm-6"><img src="https://dummyimage.com/300x300/000/fff" alt="" style="display: block; height: 250px; width: 250px; margin: 5px;"></div>Something else</li>
<li><div class="col-lg-2 col-sm-6"><img src="https://dummyimage.com/300x300/000/fff" alt="" style="display: block; height: 250px; width: 250px; margin: 5px;"></div>Something else</li>
<li><div class="col-lg-2 col-sm-6"><img src="https://dummyimage.com/300x300/000/fff" alt="" style="display: block; height: 250px; width: 250px; margin: 5px;"></div>Something else</li>
</ul>