Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Flexbox Layout Flexbox Properties Vertical and Horizontal Centering

Question about Centering

why is it important to use both of these together ?

  • justify-content: center;
  • align-items: center

Does it make to use either justify-content or align-items?

2 Answers

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,373 Points

More specifically :

justify-content is for the main-axis ( horizontally if flex-direction: row, and vertically if flex-direction: column)

align-items is for the cross-axis ( vertically if flex-direction: row, and horizontally if flex-direction: column)

Hope i could help you.

One aligns the items horizontally, the other vertically.

Here is a great explanation on stackoverflow.

This website shows a more practical answer http://www.sketchingwithcss.com/samplechapter/cheatsheet.html