html - 如何将 div 中的文本从 div 居中
问题描述
我有这种情况:
<div id="main">
<div id="my-items">
<div class=m id="id1">
Smth here(1)
</div>
<div class=m id="id2">
Smth here(2)
</div>
<div class=m id="id3">
Smth here(2)
</div>
...
</div>
</div>
我有未确定的 div 数量(div 的子项(div 的子项))
我想垂直对齐文本(在他的 div 中(第一个文本 - #id1,第二个文本 - #id2 ...))!我尝试使用vertical-align: middle;
. 请创建一个 jsfiddle 或 codepen 示例!
CSS:
.m{
height:32px;
width:90px;
text-align: center;
}
#my-items{
max-height:400px;
width:90px;
text-align:center;
}
解决方案
以你的#my-items 风格试试这个
position: absolute;
top: 50%;
推荐阅读
- android - WebView Woocommerce 购物车页面
- api - Angular 6 - 同步调用多个 API
- docusignapi - DocuSign API - DocuSign 自动更改收件人电子邮件地址
- mysql - 无论 group_concat_max_len 大小如何,有没有办法获取以逗号分隔的列值?
- sass - 根据按钮单击更改 scss 变量值
- amazon-web-services - AWS CodePipeline CodeBuild SAM Lambda
- mysql - 如果列在mysql中有多个用逗号分隔的值,如何传入where条件
- javascript - 如何在外部js文件中使用ts文件
- webpack - Webpack SCSS @charset 和 @import 问题
- sql-server - 当点击后没有响应时,如何在 SQL Server 2017 中停止导入和导出向导