CSS Grid - 4 Squares Layout

By Christine Siu

F6
#
How do I use This?

A four section layout that stacks on smaller screens.

HTML
<div class="container">
  <div class="grid-1 callout primary">
    Square 1
  </div>

  <div class="grid-2 callout warning">
    Square 2
  </div>

  <div class="grid-3 callout alert">
    Square 3
  </div>

  <div class="grid-4 callout success">
    Square 4
  </div>
</div>

.container {
  display: grid;
  grid-template-rows: repeat(2, 1fr);
  grid-template-columns: repeat(4, 1fr);
  width: 100vw;
  height: 100vh;
  @media screen and (max-width: 60em) {
    grid-template-rows: repeat(4, 1fr);
  }
}

// .grid-1,
// .grid-2,
// .grid-3,
// .grid-4 {
//   grid-template-rows: repeat(6, 1fr);
//   grid-template-columns: repeat(6, 1fr);
// }
.grid-1 {
  grid-column-start: 1;
  grid-column-end: 3;
  grid-row: 1;
  @media screen and (max-width: 60em) {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row: 1;
  }
}

.grid-2 {
  grid-column-start: 3;
  grid-column-end: 5;
  grid-row: 1;
  @media screen and (max-width: 60em) {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row: 2;
  }
}

.grid-3 {
  grid-column-start: 1;
  grid-column-end: 3;
  grid-row: 2;
  @media screen and (max-width: 60em) {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row: 3;
  }
}

.grid-4 {
  grid-column-start: 3;
  grid-column-end: 5;
  grid-row: 2;
  @media screen and (max-width: 60em) {
    grid-column-start: 1;
    grid-column-end: 5;
    grid-row: 4;
  }
}

.callout {
  margin: 0;
}


.container {
  display: -ms-grid;
  display: grid;
  -ms-grid-rows: (1fr)[2];
      grid-template-rows: repeat(2, 1fr);
  -ms-grid-columns: (1fr)[4];
      grid-template-columns: repeat(4, 1fr);
  width: 100vw;
  height: 100vh;
}

@media screen and (max-width: 60em) {
  .container {
    -ms-grid-rows: (1fr)[4];
        grid-template-rows: repeat(4, 1fr);
  }
}

.grid-1 {
  -ms-grid-column: 1;
      grid-column-start: 1;
  grid-column-end: 3;
  -ms-grid-row: 1;
      grid-row: 1;
}

@media screen and (max-width: 60em) {
  .grid-1 {
    -ms-grid-column: 1;
        grid-column-start: 1;
    grid-column-end: 5;
    -ms-grid-row: 1;
        grid-row: 1;
  }
}

.grid-2 {
  -ms-grid-column: 3;
      grid-column-start: 3;
  grid-column-end: 5;
  -ms-grid-row: 1;
      grid-row: 1;
}

@media screen and (max-width: 60em) {
  .grid-2 {
    -ms-grid-column: 1;
        grid-column-start: 1;
    grid-column-end: 5;
    -ms-grid-row: 2;
        grid-row: 2;
  }
}

.grid-3 {
  -ms-grid-column: 1;
      grid-column-start: 1;
  grid-column-end: 3;
  -ms-grid-row: 2;
      grid-row: 2;
}

@media screen and (max-width: 60em) {
  .grid-3 {
    -ms-grid-column: 1;
        grid-column-start: 1;
    grid-column-end: 5;
    -ms-grid-row: 3;
        grid-row: 3;
  }
}

.grid-4 {
  -ms-grid-column: 3;
      grid-column-start: 3;
  grid-column-end: 5;
  -ms-grid-row: 2;
      grid-row: 2;
}

@media screen and (max-width: 60em) {
  .grid-4 {
    -ms-grid-column: 1;
        grid-column-start: 1;
    grid-column-end: 5;
    -ms-grid-row: 4;
        grid-row: 4;
  }
}

.callout {
  margin: 0;
}

JS