html - 为什么 flex 中的 `align-items:center` 不能将内部元素作为一个整体垂直居中?
问题描述
*{
margin:0;
padding:0;
}
#main{
margin:0 auto;
width:300px;
height:180px;
border:1px solid red;
display:flex;
flex-direction:column;
justify-content:center;
align-items:center;
}
#inner{
width:100px;
height:40px;
line-height:40px;
border:1px solid red;
text-align:center;
margin-bottom:10px;
}
<div id="main">
<div id="inner">inner box</div>
<img src="https://i.stack.imgur.com/VOK9C.png" alt="">
</div>
我想将主 div 中的内部 div 和图像作为一个整体垂直居中。
flex-direction:column;
使列作为我的 flex 方向,justify-content:cneter;
水平居中主 div 中的所有内部元素。
为什么align-items:center
在 flex 中不能将内部元素作为一个整体垂直居中?
解决方案
中有一个错字justify-content:cneter;
。更改cneter
为:center
。
推荐阅读
- swift - Swift 编译器用 1 个数组(>30 秒)编译简单程序的时间太长
- regex - AWS API Gateway 中的 Unicode 字符验证
- node.js - 带有 NodeJS 的 Mailchimp API - 将成员添加到列表返回我“错误:getaddrinfo ENOTFOUND”
- c++ - 在 1.5 秒内找到超过 2000 万个 3 到 4 个不同整数的中位数
- python - Wagatail 2.1 (Django) 来自 Snippet 的自定义设置访问
- php - 如何将数据库中的值放入表中的特定列
- swift - Swift function with both completion handler and return
- unity3d - 将 3D 矢量相对于另一个 3D 矢量旋转 90 度
- javascript - 获取 PDF 的异步 api 调用返回空白 PDF
- python - 已知“keys”和“root”如何用于记录配置