Flexbox is a layout model for arranging items (horizontally or vertically) within a container, in a flexible and responsive way.
Flexbox makes it easy to design a flexible and responsive layout, without using float or positioning.
There is a set of CSS classes part of
NatSkin to help with
CSS Flexbox Layouts. Note that all classes use the
foswikiFlex... prefix
as they are of general use not restricted to
NatSkin.
A flexbox layout consists of a container and its items. There are classes to be used on a container and some that only make
sense for child items within that container:
Container Classes
Name |
Description |
| Wrap |
| Justify |
| Gap |
foswikiInlineFlex |
same but container is an inline-block |
foswikiFlexWrapReverse |
wrap items bottom up |
foswikiFlexWrap |
wrap items at the end of their axis |
foswikiFlexRowReverse |
horizontal axis, right to left |
foswikiFlexRow |
horizontal axis along which items float left to right (default) |
foswikiFlexNoWrap |
don't wrap items (default) |
foswikiFlexNoGap |
no gap between items (default) |
foswikiFlexJustifyStart |
items are aligned left (default) |
foswikiFlexJustifyEnd |
items are aligned right, extra before them |
foswikiFlexJustifyCenter |
center items, extra space at start and end |
foswikiFlexJustifyBetween |
between items |
foswikiFlexJustifyArround |
distribute extra space around items |
foswikiFlexItemsStretch |
stretch all items (default) |
foswikiFlexItemsStart |
align items at the start of the cross axis |
foswikiFlexItemsEnd |
align items at the end |
foswikiFlexItemsCenter |
center items |
foswikiFlexItemsBaseline |
align items to the text's baseline |
foswikiFlexGap5 |
margin factor 1 |
foswikiFlexGap4 |
margin factor 0.8 |
foswikiFlexGap3 |
margin factor 0.6 |
foswikiFlexGap2 |
margin factor 0.4 |
foswikiFlexGap |
margin between items using a factor 0.2 of --margin |
foswikiFlexContentStretch |
stretch items to take up the remaining space |
foswikiFlexContentStart |
pack items to the start, similar to foswikiFlexJustifyStart |
foswikiFlexContentEnd |
pack items to the end |
foswikiFlexContentCenter |
center items |
foswikiFlexContentBetween |
put space between items |
foswikiFlexContentAround |
put space around items |
foswikiFlexColumnReverse |
vertical axis, bottom up |
foswikiFlexColumn |
vertical axis, top down |
foswikiFlex |
activates flexbox layout for all contained items |
| Direction |
| Align Items |
| Align Content |
Item Classes
| Name |
Description |
foswikiFlexStretch |
grow the current item and create a new flexbox for its own child items |
| Base |
foswikiFlexBase2 |
item's default size is 50% of container witdth |
foswikiFlexBase3 |
33% of container width |
foswikiFlexBase4 |
25% |
foswikiFlexBase5 |
20% |
| Grow/Shring |
foswikiFlexGrow |
defines the ability of the item to grow if necessary |
foswikiFlexShrink |
shrink the element if necessary |
foswikiFlexAuto |
automatically grow the item |
foswikiFlexNoGrow |
don't grow the item |
foswikiFlexNoShrink |
dont' shrink the item |
| Align Self |
foswikiFlexSelfStart |
override alignment specified by the container by aligning it to start |
foswikiFlexSelfEnd |
align item to end |
foswikiFlexSelfCenter |
center item |
foswikiFlexSelfBaseline |
align item to the text's baseline |
foswikiFlexSelfStretch |
stretch item |
foswikiFlexSelfAuto |
use default alignment as specified by the container |
| Order |
foswikiFlexNoOrder |
items are laid out by its source order |
foswikiFlexOrder1 |
order 1 |
foswikiFlexOrder2 |
order 2 |
foswikiFlexOrder3 |
... |
foswikiFlexOrder4 |
... |
foswikiFlexOrder5 |
... |
foswikiFlexOrder6 |
... |
foswikiFlexOrder7 |
... |
foswikiFlexOrder8 |
... |
foswikiFlexOrder9 |
... |
foswikiFlexOrder10 |
... |
foswikiFlexOrderLast |
order item to the end |
Examples
You type:
<div class='foswikiFlex foswikiFlexWrap foswikiFlexGap alt'>
<div class='foswikiFlexBase2'>hello world</div>
<div class='foswikiFlexBase2'>hello world</div>
<div class='foswikiFlexBase3'>hello world</div>
<div class='foswikiFlexBase3'>hello world</div>
<div class='foswikiFlexBase3'>hello world</div>
<div class='foswikiFlexBase4'>hello world</div>
<div class='foswikiFlexBase4'>hello world</div>
<div class='foswikiFlexBase4'>hello world</div>
<div class='foswikiFlexBase4'>hello world</div>
<div class='foswikiFlexBase5'>hello world</div>
<div class='foswikiFlexBase5'>hello world</div>
<div class='foswikiFlexBase5'>hello world</div>
<div class='foswikiFlexBase5'>hello world</div>
<div class='foswikiFlexBase5'>hello world</div>
</div>
You get:
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world