带显示的div:flex不是以子div为中心

时间:2017-07-07 07:35:56

标签: html css flexbox

我有一个display: flex的div,我想在行中心显示输出。出于某种原因,它显示左侧。我希望imgBoxBotimgBot div内居中。但text-align: center仅将文字置于imgBoxBot内,我如何将实际div居中?



#imgBot {
  position: absolute;
  height: 100px;
  width: 100%;
  bottom: 0;
  display: flex;
  flex-direction: row;
  text-align: center;
}

#imgBoxBot {
  height: 100px;
  width: 100px;
}

<div id="imgBot">
  <div id="imgBoxBot">
    test
  </div>
  <div id="imgBoxBot">
    test
  </div>
</div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

使用justify-content: center。您可以找到更多信息here

#imgBot {
  position: absolute;
  height: 100px;
  width: 100%;
  bottom: 0;
  display: flex;
  flex-direction: row;
  justify-content: center;
}

.imgBoxBot {
  height: 100px;
  width: 100px;
}
<div id="imgBot">
  <div class="imgBoxBot">
    test
  </div>
  <div class="imgBoxBot">
    test
  </div>
</div>