Home > UI/UX Development > CSS > How to use flex properties? – Part 2

How to use flex properties? – Part 2

Click here more details about “How to use flex properties? – Part 1” article

Parent flex container properties


5. justify-content

This property used to align the flex items.

{ justify-content: flex-start | flex-end | center | space-around | space-between | space-evenly }

This property horizontally aligns all flex items when items do not use all available space.

– See usage and the differences shown in the below examples.

justify-content: flex-start

CSS

HTML

justify-content: flex-start

flex-start: flex items display towards start of the line. This is default value of “justify-content” property.

justify-content: flex-end

CSS

HTML

justify-content: flex-end

flex-end: flex items display towards end of the line.

justify-content: center

CSS

HTML

justify-content: center

center: flex items display centered of the line.

justify-content: space-around

CSS

HTML

justify-content: space-around

space-around: flex items distributed evenly with equal space around the each flex item. Each item applies its own spacing.

justify-content: space-between

CSS

HTML

justify-content: space-between

space-between: flex items with space distributed evenly between lines, first item is on the start line and last item is on the end line.

justify-content: space-evenly

CSS

HTML

justify-content: space-evenly

space-evenly: flex items distributed in equal spacing between any two items.


6. align-items

{ align-items: flex-start | flex-end | center | stretch | baseline }

This property vertically aligns all flex items when items do not use all available space.

– See usage and the differences shown in the below examples.

align-items: flex-start

CSS

HTML

align-items: flex-start

flex-start: Items inside flex container align at the top of the container.

align-items: flex-end

CSS

HTML

align-items: flex-end

flex-end: Items inside flex container align at the bottom of the container.

align-items: center

CSS

HTML

align-items: center

center: Items inside flex container displays vertically centered.

align-items: stretch

CSS

HTML

align-items: stretch

stretch: All flex items are stretch to fit the container.

align-items: baseline

CSS

HTML

align-items: baseline

baseline: All flex items align at the baseline of the flex container.


7. align-content

{ align-content: flex-start | flex-end | center | stretch | space-between | space-around }

This property modifies the behavior of the “flex-wrap” property. It is similar as the property of “align-items”, but it aligns flex lines not flex items.

Note: This property only work is there is multiple lines of flex items. There is no effect on one line flex items.

– See usage and the differences shown in the below examples.

align-content: flex-start

CSS

HTML

align-content: flex-start

flex-start: All lines align toward the start of the flex container.

align-content: flex-end

CSS

HTML

align-content: flex-end

flex-end: All lines align toward the end of the flex container.

align-content: center

CSS

HTML

align-content: center

center: All lines displays vertically centered.

align-content: stretch

CSS

HTML

align-content: stretch

stretch: All lines equally stretch to take up the remaining space.

align-content: space-between

CSS

HTML

align-content: space-between

space-between: All lines evenly distributed in the flex container.

align-content: space-around

CSS

HTML

align-content: space-around

space-around: All lines evenly distributed in the flex container with equal space applies around each line.

Click to see demo page for all the above examples.

This Article is TAGGED in . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">