Remove empty space in CSS Grid

前端 未结 1 1388
难免孤独
难免孤独 2021-01-25 09:29

I have the following layout:



        
1条回答
  •  后悔当初
    2021-01-25 10:13

    Create a grid with, let's say, 25 small rows. Something like this:

    grid-template-rows: repeat(25, 10px);
    

    Make the "top" (green) item span four rows.

    .top {
        grid-row: 1 / 4;
    }
    

    Make the "bottom" (red) item span the remaining rows.

    .bottom {
        grid-row: 6 / -1;
    }
    

    (Starting at row 6 to make space for the 20px row gap you had originally.)

    Make the "right" (blue) item span all rows.

    .right {
        grid-row: 1 / -1;
    }
    

    revised codepen

    .grid {
      display: grid;
      grid-template-columns: 645px 316px;
      grid-template-rows: repeat(25, 10px);
      grid-column-gap: 20px;
    }
    
    .top {
      grid-column: 1 / 2;
      grid-row: 1 / 4;
      background-color: green;
    }
    
    .right {
      grid-column: 2;
      grid-row: 1 / -1;
      background-color: blue;
    }
    
    .bottom {
      grid-column: 1;
      grid-row: 6 / -1;
      background-color: red;
    }
    top
    a
    a
    a
    a
    a
    a
    a
    a
    a
    a
    bottom

    0 讨论(0)
提交回复
热议问题