Skip to content

Instantly share code, notes, and snippets.

@josemunozr
Created January 30, 2018 14:43
Show Gist options
  • Save josemunozr/c6c4adbb88022b2a3d2b5a04a7893b93 to your computer and use it in GitHub Desktop.
Save josemunozr/c6c4adbb88022b2a3d2b5a04a7893b93 to your computer and use it in GitHub Desktop.
css-grid-example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Css Grid example</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="box box-1">box 1</div>
<div class="box box-2">box 2</div>
<div class="box box-3">box 3</div>
<div class="box box-4">box 4</div>
<div class="box box-5">box 5</div>
</div>
</body>
</html>
body {
background: #333333;
font-size: 16px;
}
.container {
display: grid;
grid-template-columns: 100px auto 100px;
grid-template-rows: repeat(3, 100px);
grid-gap: 1rem;
grid-template-areas:
"box1 box1 box1"
"box2 box3 box4"
". box5 ."
}
.box {
background-color: #eaeaea;
}
.box-1 {
grid-area: box1;
}
.box-2 {
grid-area: box2;
}
.box-3 {
grid-area: box3;
}
.box-4 {
grid-area: box4;
}
.box-5 {
grid-area: box5;
}
@media only screen and (max-width: 320px){
.container {
grid-template-columns: auto;
grid-template-rows: repeat(5, 50px);
grid-template-areas:
"box1"
"box2"
"box3"
"box4"
"box5"
}
}
@media only screen and (min-width: 768px){
.container {
grid-template-columns: repeat(4, 1fr);
}
.box-1 {
grid-row: 1 / 2;
grid-column: 3 / 5;
background-color: #cccccc
}
.box-2 {
grid-row: 1 / 3;
grid-column: 1 / 3;
background-color: #888585
}
.box-3 {
grid-row: 2 / 3;
grid-column: 3 / 5;
background-color: #7a6464
}
.box-4 {
grid-row: 3 / 4;
grid-column: 1 / 2;
background-color: #524c4c
}
.box-5 {
grid-row: 3 / 4;
grid-column: 2 / 4;
background-color: #d47e7e
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment