I have the following list in grid which works so well, but I haven't been able to centralize it according the green section. I've already tried to use flex
, but it didn't work. Could anybody help me kindly?
EDIT: I've added more itens to the list, once that it grid adjust itself to show more itens in rows. When I've tried to use the codes indicated in the answers, the grid is centralized, but in only one row (and I don't know if it is possible to centralize it with more than one row in the grid).
I inserted below my main code showing what I have done until now.
section {
background: green
}
#related-posts ul {
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(auto-fill, minmax(min(7.1rem, 100%), 1fr));
justify-items: center;
}
#related-posts ul li {
display: inline-block;
text-align: center;
vertical-align: top;
}
.pthumb img {
height: 97px;
width: 129px;
object-fit: cover;
}
<section>
<div id="related-posts">
<ul>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 1</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 2</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 3</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 4</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 5</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 6</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 7</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 8</a>
</li>
<li>
<div class="pthumb">
<a href="#">
<img src="https://i0.wp.com/afrolady.com/wp-content/uploads/2020/04/Christians-1.jpeg">
</a>
</div>
<a href="#">Item 9</a>
</li>
</ul>
</div>
</section>