I’m having trouble centering my container’s item.
I need to align the third item to the center using display: grid
.
I’ve already tried to use flexbox, but it looks worse for a responsive website.
.projetos {
flex-direction: column;
padding: 3rem 3%;
text-align: center;
justify-content: center;
}
.projetos-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 2rem;
text-align: center;
}
.projetos-box img {
width: 100%;
max-width: 40rem;
border-radius: 1rem;
}
<section class="projetos" id="projetos">
<h2>Projetos <span>Recentes</span></h2>
<div class="projetos-container">
<div class="projetos-box">
<img src="https://via.placeholder.com/200.jpg" alt="" width="500">
</div>
<div class="projetos-box">
<img src="https://via.placeholder.com/200.jpg" alt="" width="500">
</div>
<div class="projetos-box">
<img src="https://via.placeholder.com/200.jpg" alt="" width="500">
</div>
</div>
</section>
2
Answers
display: flex;
flex-wrap: wrap
to allow a break to a new rowjustify-content: center
on the flex-containerYou may trick it and use transform but need to check a few things .
But it is basicly a flex job i would say 🙂
here is below a few test to demonstrate the idea and not mind about how many children you have in your grid.
If you dislike the transform trick, span this last odd element through both columns and give an auto margin.