Skip to content
CoursesWeb Forum

Flexbox items will not wrap onto the next line on mobile

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

Short answer

Hello. I am building a row of product cards with flexbox. On desktop it is fine. On my phone (375px wide) the cards do not go to the next line. They stay in one row and the page scrolls sideways.

Written by Gaelle R. ·
CiteCoursesWeb Forum, "Flexbox items will not wrap onto the next line on mobile", https://coursesweb.net/forum/t/flexbox-items-will-not-wrap-onto-the-next-line-on-mobile/, accessed 2026-11-26.
  1. Member ·
    .cards {
      display: flex;
      gap: 16px;
    }
    .card {
      flex: 0 0 260px;
      padding: 16px;
      background: #f4f4f4;
    }
    
    <div class="cards">
      <div class="card">One</div>
      <div class="card">Two</div>
      <div class="card">Three</div>
    </div>
    

    I expected the third card to go below the others. In DevTools the .cards box is 375px wide, but each card is 260px, so they go outside of it. I tried width: 100% on .card, but then my desktop layout is broken. What am I missing? Thank you.

    0
    ReplyLink

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

  1. Ferdi K.Member ·

    Had the exact same thing on my first portfolio page. What fixed it for me (attempt number 4) was putting overflow-x: hidden on the body. The sideways scroll is gone and it looks fine on my phone now.

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