search

Home  >  Q&A  >  body text

How can I implement a grid system in my divs using CSS Grid?

I want to create a div with 2 columns, when I add an item in the parent div it should be in the first column, when the first column has 3 elements and I want to add other items it should Located in the second column. This is the image I'm looking for:

I found no response on the internet, I tried the css grid generator but without any results..

CSS Grid Generator but I can't get the right answer

P粉195200437P粉195200437485 days ago497

reply all(2)I'll reply

  • P粉427877676

    P粉4278776762023-09-09 00:57:36

    Ok...it looks like you just have a problem with mesh flow. To change it, use grid-auto-flow:column; That's it, the grid's flow will change from rows to columns. You can change grid-template-rows as needed.

    reply
    0
  • P粉469090753

    P粉4690907532023-09-09 00:09:36

    What you need to do in html is:

    <div class="parent">
       <div class="child">1</div>
       <div class="child">2</div>
       <div class="child">3</div>
       <div class="child">4</div>
       <div class="child">5</div>
       <div class="child">6</div>
    </div>

    and CSS:

    .parent{
         display:grid;
         grid-template-columns: 1fr 1fr;
         grid-auto-flow: column;
         grid-template-rows:1fr 1fr 1fr;
     }

    Demo

    reply
    0
  • Cancelreply