html - 如何让这个div居中对齐?

标签 html css flexbox

<分区>

我有这个标记

.course-flex-container {
  display: flex;
  flex-direction: column;
  margin: 5px 5px 5px 5px;
  background-color: red;
}

.course-flex-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.course-flex-row-2 {
  display: flex;
  flex-direction: row;
}
<div class="course-flex-container">
  <div class="course-flex-row">
    <div>edit</div>
    <div>delete</div>
  </div>
  <div class="course-flex-row-2">
    <div>Read Chapter 1 to 3</div>
  </div>
  <div class="course-flex-row">
    <div>Blaw 3100</div>
    <div>Due Date: 6/29/2017</div>
  </div>
</div>

我试图对齐 <div>Read Chapter 1 to 3</div>但是当我使用 text-align: center; 时它不会居中对齐我试过那个 div和它的 parent div .

我删除了 text-align来 self 的代码,因为它无法正常工作,这就是您看不到它的原因。

最佳答案

使用justify-content: center.course-flex-row-2

.course-flex-container {
  display: flex;
  flex-direction: column;
  margin: 5px 5px 5px 5px;
  background-color: red;
}

.course-flex-row {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.course-flex-row-2 {
  display: flex;
  flex-direction: row;
  justify-content: center;
}
<div class="course-flex-container">
  <div class="course-flex-row">
    <div>edit</div>
    <div>delete</div>
  </div>
  <div class="course-flex-row-2">
    <div>Read Chapter 1 to 3</div>
  </div>
  <div class="course-flex-row">
    <div>Blaw 3100</div>
    <div>Due Date: 6/29/2017</div>
  </div>
</div>

关于html - 如何让这个div居中对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44851692/

上一篇:html - 将所有内容置于 div 中间,文本位于图像的顶部和底部

下一篇:html - 当 CSS 中根本不使用 position 属性时,定义 'position: relative' 有什么区别?

相关文章:

javascript - 需要居中整个导航栏,包括子菜单,找不到正确的代码。我的 JavaScript 搞砸了吗?

javascript - 使用 JQuery 设置 CSS 关键帧

.net - @font-face 在本地主机上工作正常,但在 AppHarbor 中不行

html - 带有几个方 block 的 Flexbox 任务和 @media 变化低于 600px

javascript - 如何使用 socket.io 包含外部 javascript 客户端?

javascript - jQuery如何设置点击div中的href?

html - 使用位置 : sticky 不粘贴图像

html - .woff 和 .tff 的链接在缩小后不起作用

html - Flexbox 两行宽度相同且溢出

html - 页面调整大小后无法将 flexbox 容器拉到页脚