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 Cells

The cards touch each other. We could give each card a margin, but there's a better way, which you know from flexbox: the gap property. It sets the space between the rows and the columns of the grid.

.cards {
	gap: 1rem;
}

The gaps are only between the cells, never at the edges of the grid, so the outer cards stay lined up with the rest of the page. The browser takes the gaps away from the width first, and the fr columns share what's left.

With two values, the first one is the gap between the rows and the second one the gap between the columns: gap: 2rem 1rem. Each of them can also be set on its own, with the row-gap and column-gap properties.

Instructions

  1. 1

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

  2. 2

    Make the gap between the rows a bit bigger than the gap between the columns: change the value of gap to 1.5rem 1rem.

Back

3/7

  1. 1. Grid Container and Items
  2. 2. The fr Unit
  3. 3. Gaps Between Cells
  4. 4. Spanning Several Cells
  5. 5. Page Layout with Areas
  6. 6. Flexbox or Grid?
  7. 7. Summary
Next

Try it yourself

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