Home

Awesome

SUIT CSS utilities: flex

Build Status

SUIT CSS flexbox utilities

Installation

Available classes

flex-container

flex-direction

flex-wrap

justify-content

align-items

align-content

align-self

order

flex-grow

X can be any of the following numbers: 1, 2, 3, 4, 5.

flex-shrink

X can be any of the following numbers: 0, 1, 2, 3, 4, 5.

flex-basis

Used to override other utilities and tweak how space is distributed.

flex shorthand

Aligning with auto margins

Read more about how this works.

Plugins

All flex utilities can be limited to specific Media Query breakpoints.

<div class="u-md-flex u-md-flexWrap">
  <!-- flex items -->
</div>

Configuration

There are 3 Media Query breakpoints:

When using postcss-custom-media, breakpoints can be configured using @custom-media. For example:

@custom-media --sm-viewport (min-width:320px) and (max-width:640px);
@custom-media --md-viewport (min-width:640px) and (max-width:960px);
@custom-media --lg-viewport (min-width:960px);

Usage

Centring an element in its container

<div class="u-flex u-flexAlignItemsCenter u-flexJustifyCenter">
  <p>Some centred content</p>
</div>

Usage with Grid

Note: The Grid component already sets display: flex on the root element.

<div class="Grid Grid--alignBottom">
  <div class="Grid-cell u-size1of3 u-md-flexAlignSelfCenter">Content</div>
  <div class="Grid-cell u-size1of3">Content</div>
  <div class="Grid-cell u-size1of3">Content</div>
</div>

Usage with utils-size

<div class="u-flex u-flexJustifyEnd">
  <div class="u-size4of12">Content</div>
  <div class="u-size2of12">Content</div>
  <div>Content</div>
</div>
<div class="u-flex u-flexAlignItemsCenter">
  <div class="u-size1of4">Content</div>
  <div class="u-size1of4">Content</div>
  <div class="u-sizeFill">Content</div>
</div>

Please refer to the README for SUIT CSS utils

Setting flex-shrink in IE10

In IE10 it is required to explicitly set flex-shrink on flex items, or use the longhand flex declaration.

In prior versions of utils-flex this was set automatically on all flex items. Due to issues with specificity this has been removed.

Should you need to apply the fix for IE10 then add a u-flexShrink class manually:

<div class="u-flex u-flexNoWrap">
  <div class="FlexItem u-flexShrink1">Content</div>
  <div class="FlexItem u-flexShrink1">Content</div>
</div>

Testing

Install Node (comes with npm).

npm install

To generate a build:

npm run build

To lint code with postcss-bem-linter and stylelint

npm run lint

To generate the testing build.

npm run build-test

To watch the files for making changes to test:

npm run watch

Basic visual tests are in test/index.html.

Browser support

Refer to the caniuse page for flexbox.