Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Cross Axis Alignment

The logo and the links are at the two ends of the navigation bar now, but they're both stuck to its top edge, and the links aren't even level with the logo. We'd like them in the middle of the bar's height.

The position of the items on the cross axis is set by the align-items property of the flex container. In a row, the cross axis goes from top to bottom, so align-items moves the items up and down:

stretch: the items are stretched along the whole cross axis, so in a row, they're as tall as the container. Only items without a set height are stretched. This is what you get when you don't set align-items.

flex-start: the items are at the start of the cross axis (in a row, at the top), and they're only as tall as their content.

center: the items are in the middle.

flex-end: the items are at the end (in a row, at the bottom).

Our logo and links are stretched to the full height of the navigation bar, but their text stays at the top of each of them. That's why they look stuck to the top.

Stretching is useful too: thanks to it, all our breed cards are equally tall, even though some of them have more text than others. Scroll down and have a look.

Instructions

  1. 1

    In the rule for .navigation, add the declaration align-items: center. The logo and the links move to the middle of the bar's height.

Back

3/8

  1. 1. Flex Container
  2. 2. Main Axis Alignment
  3. 3. Cross Axis Alignment
  4. 4. Direction and Centering
  5. 5. Gaps Between Items
  6. 6. Wrapping Items
  7. 7. Growing Items
  8. 8. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.