background
loading scroll to btns
Back To Home
article
2 min readOctober 20, 2023

๐Ÿœ Responsive grid layout

css
html
responsivity
layout

Steps

  1. make the parent of the elements grid display:grid;
  2. add this value for grid-template-columns property of the parent grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));

The Complete Code

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: sans-serif;
}
body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #eee;
}
.container {
  width: 90%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}
.box {
  height: 200px;
  border: 3px solid green;
  background: rgba(255, 255, 0, 0.424);
  display: grid;
  place-content: center;
  position: relative;
}

References

Pen at codepen

Comments