Skip to content

Instantly share code, notes, and snippets.

@AakashRao-dev
Last active September 3, 2022 09:35
Show Gist options
  • Save AakashRao-dev/727c45ad26dc712dd5f1cd003217ce02 to your computer and use it in GitHub Desktop.
Save AakashRao-dev/727c45ad26dc712dd5f1cd003217ce02 to your computer and use it in GitHub Desktop.
The difference between auto-fit and auto-fill
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./style.css" />
<title>The difference between auto-fit and auto-fill</title>
</head>
<body>
auto-fill
<div class="auto-fill-container container">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
</div>
<hr />
auto-fit
<div class="auto-fit-container container">
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
</div>
</body>
</html>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container > div {
display: flex;
justify-content: center;
align-items: center;
font-size: 2rem;
color: #ffeead;
}
/* =============================== */
/* MAIN CSS GRID CODE */
.auto-fill-container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
grid-gap: 20px;
}
.auto-fit-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-gap: 20px;
}
/* =============================== */
html,
body {
background: #ffeead;
padding: 10px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 28px;
}
.container > div:nth-child(1n) {
background: #ce96ca;
}
.container > div:nth-child(3n) {
background: #88d8b0;
}
.container > div:nth-child(2n) {
background: #ff6f69;
}
.container > div:nth-child(4n) {
background: #ffcc5c;
}
hr {
margin: 80px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment