Understanding flexbox with tailwindcss

Flexbox treats items as a unidimensional list.

Container properties

direction

.flex.border.border-red-500
  .border.p-2.m-2 1
  .border.p-2.m-2 2
  .border.p-2.m-2 3
  .border.p-2.m-2
    4
    %br
    newline

row direction

Items are placed following a direction. Available directions:

.flex.border.border-red-500.flex-col
  .border.p-2.m-2 1
  .border.p-2.m-2 2
  .border.p-2.m-2 3
  .border.p-2.m-2
    4
    %br
    newline

col direction

wrapping

Items will be in the same line, with no wrapping. To have them wrap you should add one of:

justify-content

The arrangement of items along the axis can be set with:

These will not stretch or shrink the items.

.flex.border.border-red-500.justify-end
  .border.p-2.m-2 1
  .border.p-2.m-2 2
  .border.p-2.m-2 3
  .border.p-2.m-2
    4
    %br
    newline

justify-end

align-items

By default the items are stretched along the cross axis. You can change the alignment with

.flex.border.border-red-500.justify-between.items-end
  .border.p-2.m-2 1
  .border.p-2.m-2 2
  .border.p-2.m-2 3
  .border.p-2.m-2
    4
    %br
    newline

items-end

align-content

Similar to justify-content, but relative to the cross axis. Options:

Children properties

order

flex-grow

.flex.border.border-red-500.justify-between.items-end
  .border.p-2.m-2 1
  .border.p-2.m-2 2
  .border.p-2.m-2.flex-grow 3
  .border.p-2.m-2 4

flex-grow

flex-shrink

flex-basis

Default size of an element before the available space is redistributed.

flex

Shortcut that combines grow, shrink and basis. Its usage is recommended

align-self

Overrides the single element cross axis position.