html - flex 对齐元素 : center not centering items

标签 html css flexbox

<分区>


关闭 5 年前

Flexbox align-items: center; 不工作。

.container {
  display: flex;
  justify-content: center;
  align-self: center;
}
<div class="container">
  <p>Lorem ipsum</p>
</div>


    

最佳答案

如果您使用正确的属性并为 container 指定一个高度,它就会起作用。

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;

  /* CSS just to show the bounds */
  border: 2px solid;
  background-color: #eee
}
<div class="container">
  <p>Lorem ipsum</p>
</div>

关于html - flex 对齐元素 : center not centering items,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48516538/

上一篇:javascript - 设置 html 输入或文本区域的值

下一篇:html - 显示 : flex shows underlined icons

相关文章:

html - 如何像表格一样对齐 flex 元素?

javascript - 如何从 Django 中的 url 解析 javascript 字符串

javascript - 以表格格式显示输入字段中的数据

css - 如何制作透明标题?

html - 如何防止基于百分比的元素重叠?

CSS Grid - 为响应式屏幕格式化行和列

html - 长文本在 <td> 中正确显示,但在 &lt;input type ="text"> 中显示不正确

html - 更改 iframe 问题的背景颜色

html - 避免关键帧动画溢出导航中的子菜单

html - 为什么我的内容没有垂直对齐? ( flex ,CSS3)