Skip to content
techsnow

Layout

Flexbox Alignment

Flexbox has two axes. In a row, the main axis is horizontal and the cross axis is vertical.

PropertyAligns alongCommon values
justify-contentMain axisflex-start, center, flex-end, space-between, space-around, space-evenly
align-itemsCross axisstretch, flex-start, center, flex-end, baseline

Perfect centring

.center {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

Item properties

.search { flex: 1; }        /* grow to fill the free space */
.logo { flex-shrink: 0; }   /* never shrink */
.ad { align-self: flex-end; } /* align just this item */
.first { order: -1; }       /* move it to the start */