<main>
  <h2>Indicating Blank Grid Areas with <code>grid-template-areas</code></h2>
  <p>Use the button to toggle the grid cells defined with the <code>grid-template-areas</code> property. This grid includes two blank areas indicated with one or more consecutive dots (....) in the string value for <code>grid-template-areas</code>.</p>
  <div class="btns">
    <button>Toggle Grid Rows/Cols</button>
  </div>
  <div class="container">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
    <div class="item">4</div>
  </div>
  <div class="dir">
    <label for="ltr">left-to-right <input type="radio" value="ltr" name="direction" id="ltr" checked></label>
    <label for="rtl">right-to-left <input type="radio" value="rtl" name="direction" id="rtl"></label>
  </div>
</main>
* {
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  font-size: 20px;
  padding: 0 20px 30px;
  line-height: 1.4;
}

main {
  max-width: 800px;
  margin: 0 auto;
}

h2 {
  text-align: center;
}

code {
  font-family: Consolas, monospace;
  background: #ccc;
  padding: 1px 3px;
}

.btns {
  text-align: center;
}

button {
  margin: 0 auto 1em;
}

.container {
  border: solid 2px;
  background: #f8ddf0;
  margin-bottom: 1em;
  display: grid;
  padding: 4px;
}

.gridtemplateareas {
  grid-template-rows: 1fr 1fr 1fr 1fr;
  grid-template-columns: 1fr 2fr;
  grid-template-areas: "head head"
                       "....  main"
                       "nav   ...."
                       "nav   foot";
}

.gridtemplateareas .item:nth-child(1) {
  grid-area: head;
}

.gridtemplateareas .item:nth-child(2) {
  grid-area: main;
}

.gridtemplateareas .item:nth-child(3) {
  grid-area: nav;
}

.gridtemplateareas .item:nth-child(4) {
  grid-area: foot;
}


.ltr {
  direction: ltr;
}

.rtl {
  direction: rtl;
}

.dir {
  text-align: center;
}

label {
  margin-right: 1.3em;
  padding: 8px;
}

.item {
  background: #c565a8;
  border: solid 2px #305077;
  text-align: center;
  font-size: 2em;
  margin: 4px;
  color: white;
  font-weight: bold;
}
let container = document.querySelector('.container'),
    dirs = document.querySelector('.dir').querySelectorAll('input');

document.querySelector('button').addEventListener('click', function () {
  container.classList.toggle('gridtemplateareas');
}, false);

for (i of dirs) {
  (function(i) {
    i.addEventListener('click', function() {
      clearClasses(container, dirs);
      container.classList.add(i.value);
    }, false);
  })(i);
}

function clearClasses (el, cl) {
  for (i of cl) {
    el.classList.remove(i.value);
  }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.