CSS Clear after every nth-child

后端 未结 7 919
执念已碎
执念已碎 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:16

    sabof is right. But It will be great if you use display: inline-block instead of float:left. Please see below for example.

    .list {
      width: 300px;
      font-size: 0;
    }
    .item {
      display: inline-block;
      width: 90px;
      font-size: 16px;
      background: yellow;
      margin-right: 5px;
      margin-bottom: 10px;
      vertical-align: top;
    }
    <div class="list">
      <div class="item">Lorem ipsum dolor sit amet,</div>
      <div class="item">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
      <div class="item">Lorem ipsum dolor sit amet,</div>
      <div class="item">Lorem ipsum dolor sit amet,</div>
      <div class="item">Lorem ipsum dolor sit amet</div>
    </div>

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