reading-notes

Flexbox and Templating

Mustache

Source: Javascript Templating Language and Engine— Mustache.js with Node and Express Reference: Mustache.js documentation

Templating: fast/efficinet way to render client templates with a JSON data source.

Mustache Overview

Mustache.render("Hello, ", {name: "Logan"});
//returns: Hello, Logan

Mustache-express

var mustacheExpress = require('mustache-express');

// Register '.mustache' extension w/ The Mustache Express
app.engine('html', mustacheExpress());

app.set('view engine', 'html');
app.set('views', _dirname + '/src/views');
- /views
-- book.html
-- hello.html
-- index.html

In hello.html:

<div class="container mt-5 mb-5 p-5" style='background-color: white; opacity: 0.9'>
    <h1>Hello </h1>
</div>

Flexbox

Source: A Complete Guide to Flexbox

Gives container ability to alter its items’ width/size and order to fill avaliable space.

Flexbox Overview

flex example

Terminology

Flex Container Properties

.container {
  flex-flow: column wrap;
}
.container {
  justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly | start | end | left | right ... + safe | unsafe;
}
.container {
  align-items: stretch | flex-start | flex-end | center | baseline | first baseline | last baseline | start | end | self-start | self-end + ... safe | unsafe;
}
  .container {
  align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | start | end | baseline | first baseline | last baseline + ... safe | unsafe;
}

Flex Item Properties

.item {
  order: 5; /* default is 0 */
}
.item {
  flex-grow: 4; /* default 0 */
}
.item {
  flex-shrink: 3; /* default 1 */
}
.item {
  flex-basis:  | auto; /* default auto */
}
.item {
  flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
}
.item {
  align-self: auto | flex-start | flex-end | center | baseline | stretch;
}

Example

Centering

.parent {
  display: flex;
  height: 300px; /* Or whatever */
}

.child {
  width: 100px;  /* Or whatever */
  height: 100px; /* Or whatever */
  margin: auto;  /* Magic! */
}

Back