CSS Clear after every nth-child

后端 未结 7 920
执念已碎
执念已碎 2020-12-13 12:36

I have multiple items with same width inside a container. Because of different heights of the elements, there is problem with the alignment, you can see in image below.

7条回答
  •  独厮守ぢ
    2020-12-13 13:04

    You can use:

    .list {
      display:flex;
      flex-wrap: wrap;
      ...
    }
    

    See below:

    .list {
      width: 300px;
      overflow: hidden;
      display: flex;
      flex-wrap: wrap;
    }
    .item {
      float: left;
      width: 90px;
      background: yellow;
      margin-right: 5px;
      margin-bottom: 10px;
    }
    .item:nth-child(3) {
      background: brown;
    }
    .item:nth-child(3):after {
      content: ".";
      display: block;
      height: 0;
      clear: both;
      visibility: hidden;
    }
    Lorem ipsum dolor sit amet,
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Lorem ipsum dolor sit amet,
    Lorem ipsum dolor sit amet,
    Lorem ipsum dolor sit amet

提交回复
热议问题