Items that span all columns/rows using CSS grid layout

后端 未结 2 957
逝去的感伤
逝去的感伤 2020-12-01 14:08

With the CSS Grid Layout Module soon shipping in Firefox and Chrome, I thought that I\'d try to get a handle of how to use it.

I\'ve tried to create a simple grid wi

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 14:27

    You might use a hudge value of row to span (at least as much you believe maximum of rows could be) :

    grid-row: 1 / -1; 12/19 , still not working in FF.

    #container {
      display: grid;
      grid-auto-flow: column;
      grid-auto-rows: auto;
      grid-template-columns: [left] 4rem [right] 1fr;
      margin: 0rem auto;
      max-width: 32rem;
    }
    #a {
      background: lightgreen;
      grid-column: left;
      grid-row-start: 1;
      grid-row-end: span 1000;/* hudge value ... will at least span so many rows */
      justify-self: center;/* ? what did you mean here ? */
      /* did you mean : */
      display:flex;
      align-items:center;
    }
    #b {
      grid-area: auto / right;
      background: yellow;
    }
    #c {
      grid-area: auto / right;
      background: pink;
    }
    #d {
      grid-area: auto / right;
      background: lightskyblue;
    }
    #e {
      background: plum;
      grid-area: auto / right;
    }
    a
    b
    c
    d
    e

    or did you mean:

    #container {
      display: grid;
      grid-auto-flow: column;
      grid-auto-rows: auto;
      grid-template-columns: [left] 4rem [right] 1fr;
      margin: 0rem auto;
      max-width: 32rem;
    }
    #a {
      background: lightgreen;
      grid-column: left;
      grid-row-start: 1;
      grid-row-end: span 1000;/* hudge value ... will at least span so many rows */
      align-self: center;
      justify-self:center
      }
    #b {
      grid-area: auto / right;
      background: yellow;
    }
    #c {
      grid-area: auto / right;
      background: pink;
    }
    #d {
      grid-area: auto / right;
      background: lightskyblue;
    }
    #e {
      background: plum;
      grid-area: auto / right;
    }
    a
    b
    c
    d
    e

    Here is a codepen to play with live.

提交回复
热议问题