View on GitHub

reading-notes

Mustache and Flexbox

Links:

  1. Templating with Mustche
  2. A Guide to Flex
  3. Flexbox Froggy
  4. Mustache.js Official Documentation

Mustache Templating

HTML Mustcahe Template:

<html>
  <body onload="renderHello()">
    <div id="target">Loading...</div>
    <script id="template" type="x-tmpl-mustache">
      Hello !
    </script>

    <script src="https://unpkg.com/mustache@latest"></script>
    <script src="render.js"></script>
  </body>
</html>

JavaScript:

function renderHello() {
  var template = document.getElementById('template').innerHTML;
  var rendered = Mustache.render(template, { name: 'Luke' });
  document.getElementById('target').innerHTML = rendered;
}

Flexbox

Display

.container {
  display: flex; /* or inline-flex */
}

Flex-direction

.container {
  flex-direction: row | row-reverse | column | column-reverse;
}

Flex-wrap

.container {
  flex-wrap: nowrap | wrap | wrap-reverse;
}

Flex-flow

.container {
  flex-flow: column wrap;
}

Justify-content

.container {
  justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly | start | end | left | right ... + safe | unsafe;
}

Align-items

This defines the default behavior for how flex items are laid out along the cross axis on the current line. Think of it as the justify-content version for the cross-axis (perpendicular to the main-axis).

.container {
  align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + ... safe | unsafe;
}

Align-content

This aligns a flex container’s lines within when there is extra space in the cross-axis, similar to how justify-content aligns individual items within the main-axis.

.container {
  align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | start | end | baseline | first baseline | last baseline + ... safe | unsafe;
}

Order

By default, flex items are laid out in the source order. However, the order property controls the order in which they appear in the flex container.

.item {
  order: 5; /* default is 0 */
}

Flex-grow

This defines the ability for a flex item to grow if necessary. It accepts a unitless value that serves as a proportion. It dictates what amount of the available space inside the flex container the item should take up.

.item {
  flex-grow: 4; /* default 0 */
}

Back to Homepage