css - Flexbox 中的第一个 child 全宽

标签 css flexbox

如何将 flexbox 的第一个子元素设置为全 Angular ,并将所有其他子元素设置为 flex:1(用于拆分空间)?

像这样:

enter image description here

最佳答案

您可以将 :first-child 的宽度设置为 100%,而其余的 child :not(:first-child)flex: 1

要将它们放在多行上,请在容器上使用 flex-wrap: wrap:

.container {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  background: #e2eaf4;
  padding: 10px;
}

.child {
  display: inline-block;
  font-family: "Open Sans", Arial;
  font-size: 20px;
  color: #FFF;
  text-align: center;
  background: #3794fe;
  border-radius: 6px;
  padding: 20px;
  margin: 12px;
}

.child:first-child {
  width: 100%;
}

.child:not(:first-child) {
  flex: 1;
}
<div class="container">
  <div class="child">Child</div>
  <div class="child">Child</div>
  <div class="child">Child</div>
</div>

关于css - Flexbox 中的第一个 child 全宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41789278/

相关文章:

html - 具有奇数个元素和固定边距的 flex 网格

css - 最小宽度不适用于嵌套 Flexbox

html - Flexbox、换行和拉伸(stretch)

html - 是否可以将第二个 child 的宽度设置为行列表中最大的一个?

html - 正确设置导航菜单?

javascript - jQuery 向上滑动表行

javascript - jQuery:绑定(bind)到图像 onload 的函数获取旧的 height() 信息

css - Angular 2 Flex 布局右对齐图标

html - 如何在移动屏幕中将 col-sm-1 置于切换导航中

asp.net - 如何获得一个圆 Angular 矩形图形以跨越 ASP.NET GridView 标题行中的所有列?