Skip to content

Instantly share code, notes, and snippets.

@itsRealoj
Created October 27, 2019 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsRealoj/85a7ad13b0e91a601b9eeb362520c9a1 to your computer and use it in GitHub Desktop.
Save itsRealoj/85a7ad13b0e91a601b9eeb362520c9a1 to your computer and use it in GitHub Desktop.
Grid vs. Flexbox demo
<h1>CSS Grid</h1>
<div class="container-1">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
<h1>Flexbox (column)</h1>
<div class="container-2">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
<h1>Flexbox (row)</h1>
<div class="container-3">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
* {
font-family: Helvetica;
font-size: 1.4em;
color: white;
text-align: center;
background-color: #000;
}
.container-1 {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, auto);
margin-bottom: 50px;
}
.container-2 {
display: flex;
flex-direction: column;
margin-bottom: 50px;
}
.container-3 {
display: flex;
flex-direction: row;
}
.container-1 div:nth-child(1), div:nth-child(6) {
background-color: #B8336A;
}
.container-1 div:nth-child(2), div:nth-child(7) {
background-color: #726DA8;
}
.container-1 div:nth-child(3), div:nth-child(8) {
background-color: #7D8CC4;
}
.container-1 div:nth-child(4) {
background-color: #A0D2DB;
}
.container-1 div:nth-child(5) {
background-color: #C490D1;
}
.container-2 div:nth-child(1), div:nth-child(6) {
background-color: #B8336A;
}
.container-2 div:nth-child(2), div:nth-child(7) {
background-color: #726DA8;
}
.container-2 div:nth-child(3), div:nth-child(8) {
background-color: #7D8CC4;
}
.container-2 div:nth-child(4) {
background-color: #A0D2DB;
}
.container-2 div:nth-child(5) {
background-color: #C490D1;
}
.container-3 div:nth-child(1), div:nth-child(6) {
background-color: #B8336A;
}
.container-3 div:nth-child(2), div:nth-child(7) {
background-color: #726DA8;
}
.container-3 div:nth-child(3), div:nth-child(8) {
background-color: #7D8CC4;
}
.container-3 div:nth-child(4) {
background-color: #A0D2DB;
}
.container-3 div:nth-child(5) {
background-color: #C490D1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment