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

Gaps Between Items

Let's go back to the breed cards. They stand in a row, but they touch each other. We could separate them with margins, as we did with the links in the navigation bar (each of them has margin-left: 1rem). But a margin adds space on one side of every item, so we'd also get space in front of the first item or after the last one, where we usually don't want any.

A flex container has a better tool for this: the gap property. It sets the size of the gaps between the items, and only between them, never at the edges of the container:

.container {
	display: flex;
	gap: 2rem;
}

Just like with margins, you can use any unit you know, for example px or rem.

Instructions

  1. 1

    In the rule for .cards, add the declaration gap: 1rem.

Back

5/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.