Skip to content

Instantly share code, notes, and snippets.

@AakashRao-dev
Created September 3, 2022 08:42
Show Gist options
  • Save AakashRao-dev/bb269da43231ca8015e69d24a53835f4 to your computer and use it in GitHub Desktop.
Save AakashRao-dev/bb269da43231ca8015e69d24a53835f4 to your computer and use it in GitHub Desktop.
Explicit and implicit grid with grid-auto-row and grid-auto-column
<!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>Implict and Explicit Grid Example</title>
</head>
<body>
<div class="container">
<div>Item-01</div>
<div>Item-02</div>
<div>Item-03</div>
<div>Item-04</div>
<div>Item-05</div>
<div>Item-06</div>
<div>Item-07</div>
<div>Item-08</div>
<div>Item-09</div>
<div>Item-10</div>
<div>Item-11</div>
<div>Item-12</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;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
/* =============================== */
/* MAIN CSS GRID CODE */
.container {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(2, 100px);
grid-gap: 13px;
/* Only gets applied for the automatic
generated rows and columns */
grid-auto-columns: 200px;
grid-auto-rows: 180px;
}
/* =============================== */
html,
body {
background: #ffeead;
height: 100%;
padding: 10px;
}
.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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment