[css] Responsive cards

maurerkrisztian

Krisztián Maurer

Posted on August 7, 2022

[css] Responsive cards

It often happens that a set of cards needs to be made responsive, here is a simple solution:

https://codepen.io/maurerkrisztian/pen/dymeBmr


<div class="container">
  <div class="element">1</div>
  <div class="element">2</div>
  <div class="element">3</div>
  <div class="element">4</div>
</div>
Enter fullscreen mode Exit fullscreen mode
:root {
  --min-width: 300px;
  --space-between: 2rem;
}

.container {
  display: grid;
  grid-gap: var(--space-between);
  grid-template-columns: repeat(auto-fit, minmax(var(--min-width), 1fr));
}

.element {
  display: grid;
  place-items: center;
  background: lightpink;
  height: 100px
} 
Enter fullscreen mode Exit fullscreen mode

Maurer Krisztián demo

💖 💪 🙅 🚩
maurerkrisztian
Krisztián Maurer

Posted on August 7, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related