<main>
  <h2>Aligning Elements Along the Main Axis:<br><code>justify-content</code></h2>
  <div class="btns">
    <label for="flex-start">flex-start <input type="radio" name="justifycontent" value="flex-start" id="flex-start" checked></label>
    <label for="flex-end">flex-end <input type="radio" name="justifycontent"  value="flex-end" id="flex-end"></label>
    <label for="center">center <input type="radio" name="justifycontent"  value="center" id="center"></label>
    <label for="space-between">space-between <input type="radio" name="justifycontent"  value="space-between" id="space-between"></label>
    <label for="space-around">space-around <input type="radio" name="justifycontent"  value="space-around" id="space-around"></label>
  </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 class="item">5</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>
body {
  font-family: Arial, sans-serif;
  font-size: 20px;
  padding: 0 20px;
  line-height: 1.4;
}

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

h2 {
  margin-top: 14px;
  text-align: center;
}

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

.btns {
  padding-bottom: 1em;
  text-align: center;
}

.dir {
  text-align: center;
}

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

.container {
  border: solid 2px;
  background: #b2d5ff;
  display: flex;
  margin-bottom: 1em;
}

.ltr {
  direction: ltr;
}

.rtl {
  direction: rtl;
}

.flex-start {
  justify-content: flex-start;
}

.flex-end {
  justify-content: flex-end;
}

.center {
  justify-content: center;
}

.space-between {
  justify-content: space-between;
}

.space-around {
  justify-content: space-around;
}

.item {
  width: 15%;
  background: #007ed3;
  min-height: 100px;
  border: solid 2px #305077;
  margin: 5px;
  text-align: center;
  font-size: 4em;
  color: white;
  font-weight: bold;
  line-height: 1.4;
}
let btns = document.querySelector('.btns').querySelectorAll('input'),
    dirs = document.querySelector('.dir').querySelectorAll('input'),
    container = document.querySelector('.container');

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

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.