CSS grids: align square cells with container edges with consistent grid gap?

后端 未结 2 1123
盖世英雄少女心
盖世英雄少女心 2020-12-19 10:51

The goal is to align square cells with their container\'s leading and trailing edges while achieving a consistent gap between cells on each row, and between each row.

<
2条回答
  •  时光说笑
    2020-12-19 11:31

    This one is the answer to your first problem no need to give width to li.

    ul {
      display: grid;
      width: 260px;
      grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
      grid-auto-rows: 1fr;
      grid-gap: 10px;
      list-style-type: none;
      border: 2px solid black;
      box-sizing: border-box;
      margin: 0;
      padding: 5px;
      background: gray;
    }
    
    li {
    /*   width: 40px; */
      height: 40px;
    }

提交回复
热议问题