html - 按最后一个元素填充行中的剩余空间

标签 html css row markup

我有这样的东西:

.container {
  width: 350px;
  border: 1px solid black;
}

.item {
  display: inline-block;
  padding: 10px 20px;
  background-color: green;
}
<div class="container">
  <div class="item">
    Item 1
  </div><div class="item">
    Item 2
  </div><div class="item">
    Item 3
  </div><div class="item">
    Item 4
  </div><div class="item">
    Item 5
  </div>
</div>

我需要让最后一个元素填充行中的剩余空间。元素应按顺序放置。

(对不起我的谷歌翻译...:( )

最佳答案

您可以使用 css3 flexbox :

.container {
  flex-wrap: wrap;
  display: flex;
}
.container .item {
  /* This property will expand the last item to the remaining width */
  flex-grow: 1;
}

.container {
  flex-wrap: wrap;
  width: 350px;
  display: flex;
}

.item {
  border: 1px solid #000;
  background-color: green;
  padding: 10px 20px;
  flex-grow: 1;
}
<div class="container">
  <div class="item">
    Item 1
  </div><div class="item">
    Item 2 Item 2 Item 2
  </div><div class="item">
    Item 3
  </div><div class="item">
    Item 4
  </div><div class="item">
    Item 5
  </div>
</div>

关于html - 按最后一个元素填充行中的剩余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41258006/

相关文章:

html - 博客上的CSS图片展示

php - MySQLi 查询只返回一行

用于在悬停行上显示按钮的 Angular 2 表行悬停

Javascript通过Tag搜索XML并获取兄弟节点

javascript - 如何从 View 中删除特定 CSS 文件的引用

javascript - 使 div 更大并在悬停时向上动画更大的部分

html - 如何连接来自两个独立 div 的元素?

拉伸(stretch)窗口时 div 超出边界的 CSS 错误

javascript - 图片 :focus doesn't stay focus in CSS

mysql - DBMS 中的最大行数