Skip to content
CoursesWeb Forum

Last row of my flexbox cards spreads out with space-between

Asked by Gaelle R. · CSS Layout: Flexbox and Grid1 replyupdated

Short answer

I have a list of team cards. Three per row on desktop. I use flexbox with space-between. When there are 7 cards, the last row has one card on the left. Fine. But with 8 cards, the last row has one card at the far left and one at the far right, with a big hole in the middle.

Written by Gaelle R. ·
CiteCoursesWeb Forum, "Last row of my flexbox cards spreads out with space-between", https://coursesweb.net/forum/t/last-row-of-my-flexbox-cards-spreads-out-with-space-between/, accessed 2026-12-04.
  1. Member ·
    .team {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
    }
    .card { width: 32%; margin-bottom: 1rem; }
    

    I want the last row to start on the left like the other rows. I tried adding empty divs at the end. It works, but it is ugly and the number changes. Is there a clean CSS way?

    0
    ReplyLink

Plain text or simple Markdown. Links are nofollow. Your email is never shown.

  1. Mpho N.Member ·

    Use justify-content: flex-start and put margin-right on each card. Except the third one, so use :nth-child(3n) { margin-right: 0 }. Done.

CoursesWeb Forum. Questions and answers on learning web development: HTML, CSS, JavaScript, PHP, MySQL, Node.js and AI coding help.