Created
January 30, 2018 14:43
-
-
Save josemunozr/c6c4adbb88022b2a3d2b5a04a7893b93 to your computer and use it in GitHub Desktop.
css-grid-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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