为什么证明 - 内容在我的案例中不起作用?

时间:2016-10-13 10:42:43

标签: css flexbox justify

找不到为什么.user-name-box& .user-location div不想留在父母的中心......

.main-content{
        display: flex;
        flex-flow: row nowrap;
        justify-content: center;
        align-items: center;
        width: 600px;
        background: grey;
    }
        .user-info{
            display: inline-flex;
            flex-flow: column nowrap;
            justify-content: center;
            align-content: center;
            width: 300px;
            background: red;
        }
            .user-name-box{
                display: flex;
                width: 100px;
                height: 100px;
                background: blue;
                color: white;
            }
            .user-location{
                display: flex;
                width: 100px;
                height: 100px;
                background: yellow;
                color: black;
            }
    <div class="main-content">

        <div class="user-info">

            <div class="user-name-box">user-name-box</div>
            <div class="user-location">user-location</div>

        </div>

    </div>
    

提前致谢!

1 个答案:

答案 0 :(得分:1)

这是因为您在align-content上使用的是align-items而不是.user-info

&#13;
&#13;
.main-content {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  align-items: center;
  width: 600px;
  background: grey;
}
.user-info {
  display: inline-flex;
  flex-flow: column nowrap;
  justify-content: center;
  align-items: center;
  width: 300px;
  background: red;
}
.user-name-box {
  display: flex;
  width: 100px;
  height: 100px;
  background: blue;
  color: white;
}
.user-location {
  display: flex;
  width: 100px;
  height: 100px;
  background: yellow;
  color: black;
}
&#13;
<div class="main-content">

  <div class="user-info">

    <div class="user-name-box">user-name-box</div>
    <div class="user-location">user-location</div>

  </div>

</div>
&#13;
&#13;
&#13;