html - 带显示的div : flex is not centering child div

标签 html css flexbox

我有一个带有 display: flex 的 div ,我想在行中心显示输出。由于某种原因它显示在左侧。我想要imgBoxBot位于 imgBot 的中心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>

最佳答案

使用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>

关于html - 带显示的div : flex is not centering child div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44965117/

相关文章:

jquery - 不工作 : remove style attribute or change width\height css property via jquery in IE6\IE7\IE8

html - 使 flex 元素采用内容宽度,而不是父容器的宽度

html - 为什么 flex 元素不缩小过去的内容大小?

javascript - 我可以在没有超时的情况下使用 CSS3 和/或 javascript 隐藏/显示此菜单吗

php - 使用php发送邮件报错

html - 你如何使用 Flexbox 拉伸(stretch)和居中元素?

css - 我可以在 flexbox 中拉取元素吗?

html - IE11 Flexbox 布局在滚动容器中损坏

javascript - 更改图像数组的颜色并使用 jQuery 或 CSS 显示它们

html - 绝对定位的 div 是否有可能突破它的容器