CSS GRID: Positioning items by grid areas.

by Rodwyn Moreno

HTML

<section class="wrapper">
  <div class="header">1</div>
  <div>2</div>
  <div>3</div>
  <div class="footer">4</div>
</section>

SCSS

.wrapper {
  display: grid;
  grid-template-areas:   "header header"
                        "content sidebar"
                        "footer footer";
                        
  grid-template-rows:    75px 100vh 50px;
  grid-template-columns: 200px 1fr;                      
}

.header {
  grid-row:    header;
  grid-column: header;
}

.footer {
  grid-row:    footer;
  grid-column: footer;
}

div {
    color: #FFFFFF;
    text-align: center;
    
    &:nth-child(1) {
      background: #FF1A1A;
    }

    &:nth-child(2) {
      background: #009999;
    }
    
    &:nth-child(3) {
      background: #FF9900;
    }
    
    &:nth-child(4) {
      background: #CC66FF;
    }
    
    &:nth-child(5) {
      background: #00FF99;
    }
    
    &:nth-child(6) {
      background: #FFFF33;
    }
  }