HTML Introduction to HTML and CSS Make It Beautiful With CSS Select and Style Multiple Elements by Class

What is the display:flex and justify-content: space-around used for?

What is the display:flex and justify-content: space-around used for? Unfortunately it is not explained in video lectures. Thanks.

1 Answer

Matthew Long
Matthew Long
28,358 Points

Flex is a pretty large css concept to explain on here. You'd be better off taking a look at the guide to flexbox on css-tricks.

There is also a course solely on flex here on Treehouse.

Basically, flex is a css property that is used for layouts and positioning. The main idea behind the flex layout is to give the container the ability to alter its items' width/height (and order) to best fill the available space (mostly to accommodate to all kind of display devices and screen sizes).

The justify-content: space-around; property is where items are evenly distributed in the line with equal space around them. Note that visually the spaces aren't equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies.