html - 如何使用 flexbox 将列表定位在中心?
问题描述
我有 3 个使用 flexbox 垂直堆叠的盒子。它们现在位于左侧。我想将它们在水平方向居中。我尝试了 div {margin:10px auto} 并且它可以工作,但 css 看起来很尴尬。有没有更优雅的解决方案使用特殊的 flexbox 属性?
我想要 div 在中心。
section {
display: flex;
flex-direction: column;
background-color: teal;
}
div {
background-color: silver;
width: 200px;
margin: 10px;
line-height: 75px;
font-size: 30px;
}
<section>
<div>apple</div>
<div>banana</div>
<div>pear</div>
</section>
解决方案
你可以使用 align-items: center;
section {
display: flex;
flex-direction: column;
background-color: teal;
align-items: center;
}
div {
background-color: silver;
width: 200px;
margin: 10px;
line-height: 75px;
font-size: 30px;
}
<section>
<div>apple</div>
<div>banana</div>
<div>pear</div>
</section>
推荐阅读
- javascript - 在编写 Photoshop 脚本时打开具有 JPG 扩展名的文件夹中的所有文件
- php - php中的扩展不起作用
- alert - 在 Zabbix 中为 LLD 发现的触发器创建操作
- node.js - NodeJS:如何对依赖于其他异步调用的异步函数进行单元测试
- jquery - 如何单击 DataTables 上的任何行?
- php - 上传前在laravel上压缩视频音频图像
- django - 使用 Django Rest Framework 的辅助获取端点
- python - 如何使用无监督方法将句子分类到预定义的主题桶之一
- matlab - 如何从工作区中的变量中删除全局标志
- javascript - .data() 返回未定义