Skip to the page

MCSS-Lite 0.4.1

GitHub

Stack l-stack

StableLayout · since 0.1.0

Vertical flow: adds space between consecutive children, which keep their own width. Bare inline children (links, spans) stack too. The default way to space components vertically.

Pick this part

Pick l-stack for

  • Anything that flows top to bottom: form fields, paragraphs, a card body, a page column.
  • Changing rhythm: nest a smaller stack (l-stack--sm) inside a larger one.

Pick another part for

  • Items in a row that wrap: use l-cluster.
  • Two-dimensional layouts: use l-grid.

Build it

  1. Start with an element and add class="l-stack".
  2. Pick at most one gap modifier: --sm, --lg.
  3. Put the parts inside. The layout sets the space between them, so they need no margins.

Billing

Your plan renews on 1 March.

Show markup 7 lines
<div class="l-stack">
  <h2 class="u-margin-0">Billing</h2>
  <p class="u-margin-0">Your plan renews on 1 March.</p>
  <div class="l-cluster">
    <button type="button" class="c-button">Change plan</button>
  </div>
</div>

Check your build

Each piece that doesn't fit was run through mcss-lite validate when this page was built. The output below is real.

Fits

Let the stack own the space between its children.

Billing

Your plan renews on 1 March.

Show markup 7 lines
<div class="l-stack">
  <h2 class="u-margin-0">Billing</h2>
  <p class="u-margin-0">Your plan renews on 1 March.</p>
  <div class="l-cluster">
    <button type="button" class="c-button">Change plan</button>
  </div>
</div>

validate: 0 issues

Doesn't fit

Don't fix spacing with margins on the children.

<div class="l-stack">
  <section class="c-card" style="margin-top: 32px"><p class="u-margin-0">Plan</p></section>
</div>

validate

  • warning Components must not set their own margin. Wrap them in a layout primitive (l-stack, l-cluster…) instead. [golden-rule]

Fits

Pick the gap with a modifier.

Line one

Line two

Show markup 4 lines
<div class="l-stack l-stack--sm">
  <p class="u-margin-0">Line one</p>
  <p class="u-margin-0">Line two</p>
</div>

validate: 0 issues

Doesn't fit

Don't combine two gap modifiers.

<div class="l-stack l-stack--sm l-stack--lg">
  <p class="u-margin-0">Line one</p>
</div>

validate

  • error "l-stack--sm" and "l-stack--lg" are both gap modifiers; use only one. [exclusive-modifiers]

Spec sheet

Modifiers
ClassGroupWhat it does
l-stack--smgap (pick one)Tight spacing (0.5rem), e.g. form-field internals or list items.
l-stack--lggap (pick one)Loose spacing (2rem), e.g. between page blocks.

Fits with

Researched from