Powerful tool for distributing space and aligning content in ways that web apps and complex web pages often need.
flex-direction
justify-content
align-items
wrap
align-content
flex-grow
flex-shrink
flex-basis
align-self
order
flex
flex: initial;
flex: none;
flex: auto;
flex: <positive-number>;
flex: <grow> <shrink> <basis>;
flex: 0 1 auto;
flex: 0 0 auto;
flex: 1 1 auto;
flex: <positive-number> 1 0;
Horizontal and vertical centering
body {
display: flex;
justify-content: center;
align-items: center;
}
body
figure
Sticky footer
body {
display: flex;
flex-direction: column;
height: 100vh;
}
header {
flex: none;
}
footer {
flex: none;
}
main {
flex: auto;
}
header
body
footer
main
Media object
.media
figure
main
.media {
display: flex;
align-items: flex-start;
}
figure {
margin-right: 1em;
}
main {
flex: 1;
}
Scoreboards
body {
display: flex;
flex-direction: row;
}
.item-1, .item-3 {
flex: 1;
}
.item-2 {
flex: 2;
}
body
1
3
2
Content grouping (floating behaviour)
body {
display: flex;
flex-direction: row;
}
.item-1 {
margin-right: auto;
}
body
1
3
2
Content grouping (floating behaviour)
body {
display: flex;
flex-direction: row;
}
.item-2 {
margin-left: auto;
}
body
1
3
2
Content grouping (floating behaviour)
body {
display: flex;
flex-direction: row;
}
.item-1 {
margin-right: auto;
}
.item-3 {
margin-left: auto;
}
body
1
3
2
figure {
margin: auto;
}
body
figure
figure {
align-self: flex-end;
margin-left: auto;
}
body
figure
1
2
body {
display: flex;
}
.center, .left, .right {
display: flex;
justify-content: center;
}
.center {
flex: 3;
}
.left {
flex: 1;
justify-content: flex-start;
}
.right {
flex: 1;
justify-content: flex-end;
}
body
center
left
item
item
right
item