Only works in Chrome so far!
Horizontal orientation (
-webkit-flex-direction: row
= default value, hasn't to be stated).
The first and the third element have a predefined width, the middle takes up the remaining space. If
-webkit-flex
is stated at no element at all they are simply displayed in sequence. A height for the elements doesn't have to be stated, they always have the same height (height of the container).
The first and second element take up 1/4 of the available space (
-webkit-flex: 1
), the third takes up 2/4 (
-webkit-flex: 2
). 1 + 1 + 2 = 4/4
Vertical orientation (
-webkit-flex-direction: column
).
Can also be reversed with a value of
column-reverse
(the same goes for horizontal orientation and The first and the third element take up 1/10 of the available space, the second takes 8/10. 1 + 8 + 1 = 10/10.
The elements are aligned to the right (
-webkit-justify-content: flex-end
). Can also be centred, justified etc.
The whole container is vertically centered (
-webkit-align-content: center
). Furthermore the natural order of the elements is altered using
-webkit-order
(the first is on the third place, the second on the first and the third on the second).)
The elements can also be wrapped. If the width of the container (
width: 300px
) is smaller than the preferred width of the elements (
-webkit-flex: 80px 1
. The
1
states that the available space should be evenly distributed) than a wrap occurs.
It's also possible to state
min-width
and
max-width
(respectivley
min-height
and
max-height
) for the elements. Although
-webkit-flex
is set to
1
(which means that the available space should be evenly distributed), the first is shrinked through
max-width: 50px
and the third one is enlarged by
min-width: 500px
.
The individual elements can also be aligned vertically (
-webkit-align-self
) or the whole container altogether (with
-webkit-align-items
). Since the elements don't span the container anymore then this behavior can be reset with
-webkit-align-items: stretch
.
Another strength of flexbox is the adaptability to its content, which is a pretty enormous and initially hard to grasp topic. Therefore I don't go into it at this point but strongly advice you to read about it .
Demo by Christian Krammer, @Chris_Krammer , http://www.css3files.com