html - Flex 以第一个 child 为中心,第二个 child 在最后

标签 html css flexbox

怎么推 .right一直向右,同时保持 .centred在中心? (它不需要使用 flex,但我需要在移动 View 上保持 .centred 高于 .right)

https://codepen.io/anon/pen/rjZLOv

  <div class="flex">
      <div class="centred">
          <div class="a">asdfasdf</div>
          <div class="b">asdfasdf</div>
      </div>
      <div class="right">asdfasfad</div>
  </div>


.flex {
  display: flex;
  align-items: center;
  justify-content: center;
}

.centred {
    justify-content: center;
}

.right {
  justify-content: flex-end;
}

最佳答案

您可以制作.centred inline-block并使用 text-align: center;在父节点上使其居中,然后 float .right向右。

.container  {
  width: 1024px;
  margin: auto;
  text-align: center;
}

.centred {
  display: inline-block;
}

.right {
  float: right;
}
<div class="container">
    <div class="centred">
      <div class="a">asdfasdf</div>
      <div class="b">asdfasdf</div>
    </div>
    <div class="right">asdfasfad</div>
</div>

关于html - Flex 以第一个 child 为中心,第二个 child 在最后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42100318/

相关文章:

html - 具有多个可滚动区域的 CSS Flexbox

jquery - 检查 div 的不透明度是否为 1 jquery

css - 如何在 jquery-ui datepicker 中设置数字颜色的样式?

javascript - Q. 如何在图像层上选择一个图像?

html - 按照 BEM 约定编写 css flex 代码的最佳方法是什么?

html - 带有 float :left 的 div 的全高右边界

javascript - Jquery - $.mobile.changePage 不起作用

javascript - 循环进入 Javascript 对象并显示在表中

html - 如何将 Font Awesome 图标转换为输入类型文本

html - 将元素( flex 元素)固定到容器底部