Flexbox水平对齐项目 [英] Flexbox align items horizontally

查看:83
本文介绍了Flexbox水平对齐项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在一种以这种方式对齐子项的方法:[i] [i] ______ [i] [i] [i],无论每个组中有多少项?

Is there a method to align child items in that way: [i][i]______[i][i][i], regardless how many items are in each of the groups?

推荐答案

在Flexbox容器中

In a Flexbox Container


  • 使用 justify-content 用于水平的项目对齐。

  • 使用 align-items 以便垂直对齐项目

  • Use justify-content for the alignment of items horizontally.
  • Use align-items to align items vertically.

请看下面的示例代码段:

Have a look at the example snippet below:

.parent {
  display: flex;
  width: 100%;
  height: 100px;
  align-items: center; /* Align Items Vertically */
  justify-content: space-between; /* Align Items Horizontally (with equal space in between each of them */
  background: #eee;
}

.children {
  display: flex;
}

.child {
  margin: 0 5px;
  padding: 0 5px;
  font-size: 30px;
  background: #ccc;
  color: #000;
}

<div class="parent">
  <div class="children left-children">
    <div class="child">1</div>
    <div class="child">2</div>
    <div class="child">3</div>
  </div>
  <div class="children right-children">
    <div class="child">4</div>
    <div class="child">5</div>
    <div class="child">6</div>
  </div>
</div>

希望这会有所帮助!

这篇关于Flexbox水平对齐项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆