Floated divs won't stack properly (without gaps)

前端 未结 3 1037
温柔的废话
温柔的废话 2021-01-24 00:50

I have a container with many floated items. The problem is when the size of at least one of them changes, a gap occurs. Is there any way to force them to fill these gaps?

<
3条回答
  •  -上瘾入骨i
    2021-01-24 01:17

    You can use flexbox to fill the gaps so that every row has the same height without gaps:

    display: flex;
    flex-flow: row wrap;
    

    A working example:

    .wpr {
      padding: 20px;
      display: flex;
      flex-flow: row wrap;
    }
    
    .wpr span {
      width: calc(50% - 20px);
      min-height: 130px;
      background: green;
      margin: 10px;
      display: block;
    }
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pulvinar elit vitae lobortis tempor. Ut vitae quam maximus, iaculis lacus ut, volutpat lacus. Donec eget odio vel ligula ullamcorper hendrerit nec et arcu.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pulvinar elit vitae lobortis tempor. Ut vitae quam maximus, iaculis lacus ut, volutpat lacus.

提交回复
热议问题