New syntax of Flexible box layout module (flexbox)

Only works in Chrome so far!

.flexbox1

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).

DIV 1
DIV 2
DIV 3

.flexbox2

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

DIV 1
DIV 2
DIV 3

.flexbox3

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.

DIV 1
DIV 2
DIV 3

.flexbox4

The elements are aligned to the right ( -webkit-justify-content: flex-end ). Can also be centred, justified etc.

DIV 1
DIV 2
DIV 3

.flexbox5

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).)

DIV 1
DIV 2
DIV 3

.flexbox6

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.

DIV 1
DIV 2
DIV 3
DIV 4

.flexbox7

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 .

DIV 1
DIV 2
DIV 3

.flexbox8

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 .

DIV 1
DIV 2
DIV 3

Flexibility

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