<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 5 年前。
<分区>
编辑问题以包含 desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem .这将有助于其他人回答问题。
关闭 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/