CSS grid height wrong when using percent as grid gap

后端 未结 1 640
庸人自扰
庸人自扰 2021-01-14 11:41

I\'m using a CSS grid with images in it and wanted to set a gap between elements that scales with the size of the grid. So I set the grid-gap to 2%, but doing t

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 12:28

    the 10% seems to be honoured with flex.

    .container {
       width:90%;
       margin:0 auto;
       display:block;
    }
    
    .grid {
      display: flex;
      justify-content:space-between;
      flex-wrap:wrap;
      width:100%;
      background-color: #EEE
    }
    
    .grid-item {
      flex:0 0 45%;
      max-width:500px;
      margin:0 0 10% 0;
      display: block;
    }
    
    img.grid-item:last-of-type {
       margin-bottom:0;
    }
     

    Why does this line overlap with the grid?

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