Skip to main content
Version: Next

Flex API

This page describes how to use the attribute based flex APIs and supports three selectors: data-flex, data-flex-fill and data-flex-align.

data-flex attribute

The data-flex attribute can take the following values with their resulting CSS:

ValueCSS
<no value>flex: 1 1 0;
autoflex-basis: 100%;
growflex: 1 1 100%;
initialflex: 0 1 auto;
noneflex: 0 0 auto;
nogrowflex: 0 1 auto;
noshrinkflex: 1 0 auto;

Support for flex sizes

Additionally, you can generate flex size selectors using the mixins as shown in the following example. They will extend the data-flex attribute with numerical values, for example:

SelectorCSS
data-flex="<number>"flex: 1 1 <number>%;
e.g. data-flex="30"flex: 1 1 30%;

This can be used to give elements a width with the percentage of the numerical value in relation to their flex container.

@include fx.flex-size-attribute-selectors;
@include fx.flex-size-attribute-selectors-from-list(33 66);

The mixins can be configured with parameters to generate only the selectors you need. The first mixin can generate a range of selectors with a configurable start and end and a given increment.

The second mixin will generate only selectors for the numbers passed as the first argument.

Both mixins can generate selectors for the responsive API (e.g. data-flex-gt-sm="50")

data-flex-fill attribute

The data-flex-fill attribute can be used to make a child of a flex-container fill the entire container. It takes no arguments and adds the following properties to the element:

margin: 0;
width: 100%;
height: 100%;
min-width: 100%;
min-height: 100%;

data-flex-align attribute

The data-flex-align attribute takes the following values with their resulting CSS:

ValueCSS
startalign-self: flex-start;
centeralign-self: center;
endalign-self: flex-end;
baselinealign-self: baseline;
stretchalign-self: stretch;