Flexbox 中的第一个孩子全角

新手上路,请多包涵

如何将 flexbox 的第一个孩子设置为全角,所有其他孩子设置为 flex:1 (用于分割空间)?

像这样:

在此处输入图像描述

原文由 Dark star 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 372
1 个回答

You can set the :first-child to a width of 100% , and the rest of the childs :not(:first-child) to 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>

原文由 TheYaXxE 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题