0

I want make cards like this: https://i.stack.imgur.com/OjNIZ.jpg but I doesn't idea how to center cards.

Results: Results of my code

.cards-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 29px;
  place-items: center;
  justify-content: center;
  align-content: center;
  text-align: center;
}

.cards-container_card {
  display: grid;
  margin-top: 2em;
  text-align: center;
  border-radius: .25rem;
  width: 18rem;
}
<div class="cards-container"> - parent
  <article class="cards-container_card"> - child
    <img src="https://via.placeholder.com/80" alt="Hot air balloons">
    <div class="content">
      <h5>A short heading</h5>
    </div>
  </article>
</div>
isherwood
  • 58,414
  • 16
  • 114
  • 157

2 Answers2

1

See this codepen and hope it helps : https://codepen.io/so8800/pen/bGoQmOP

HTML :

 <div id="center">
  <div class="grid">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
  </div>
</div>

CSS:

#center {
display: grid; 
place-items: center;
}

.grid {
display : grid;
grid-template-columns : repeat(5, 180px);
grid-gap : 12px;   
}

.box {
aspect-ratio:1;
background-color:red;
}
user2305415
  • 172
  • 1
  • 3
  • 18
-1

Based on what you mean by centering the cards. You can use the 'grid-column' property to adjust the position of the cards accordingly