Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vertically justified flexbox elements

Tags:

css

flexbox

The old display:box had the ability to justify element vertically, so for N number of elements with H defined height, they will arrange themselves justified (vertically) in relation to the parent element.

Is there any way of achieving this using the current dislpay:flex system?

like image 648
vsync Avatar asked Aug 16 '15 21:08

vsync


People also ask

How do you vertically align a flex item?

Vertical and horizontal alignment By default items start from the left if flex-direction is row , and from the top if flex-direction is column . You can change this behavior using justify-content to change the horizontal alignment, and align-items to change the vertical alignment.

Which flexbox property align-items vertically?

align-items and justify-content are the important properties to absolutely center text horizontally and vertically. Horizontally centering is managed by the justify-content property and vertical centering by align-items.

Does flexbox have justify items?

The justify-content property is a sub-property of the Flexible Box Layout module. It defines the alignment along the main axis. It helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size.


1 Answers

You are looking for the flex rule justify-content: space-between;. Put that on your parent element and it will align the items so the first one touches the start of the container, the last one touches the end of the container, and the rest of the space is distributed between the elements.

You can also use align-items to align your elements in the direction perpendicular to your flex direction. For example if your flex-direction is column (vertical), then justify-content will justify items vertically and align-items will align them horizontally. Conversely if your flex-direction is row (horizontal), then justify-content will justify items horizontally and align-items will align them vertically.

More info here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

like image 146
Maximillian Laumeister Avatar answered Sep 27 '22 22:09

Maximillian Laumeister