Search code examples
cssgrid

how to swap the second row of grid items


help me please, how do i get a result like this in the grid? the result i want - link - img https://ibb.co/XbW025V . here is my code https://jsfiddle.net/o0zjuyqb/1/

<div class="container">
     <div class="parent">
       <div class="div1"></div>
       <div class="div2"></div>
       <div class="div3"></div>
       <div class="div4"></div>
       <div class="div5"></div>
       <div class="div6"></div>
      </div>
    </div>

Solution

  • You can do this by using grid-column: span 2;

    .grid {
      display: grid;
      grid-auto-flow: dense;
      grid-template-columns: 250px 290px 290px 250px;
      grid-template-rows: repeat(2, 280px);
      gap: 40px;
    }
    
    .grid div {
      background: grey;
    }
    
    .grid div.wide {
      grid-column: span 2;
      background: green;
    }
    <div class="grid">
      <div class="wide"></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div class="wide"></div>
    </div>