Bootstrap表格内容居中技巧:使用text-center类实现水平居中(table-centered类名应用于th和td元素)。使用d-flex和align-items-center类垂直对齐内容,并设置div高度匹配行高(适用于固定行高的表格)。
Bootstrap 表格内容居中:提升表格可读性
在 Bootstrap 表格中,内容居中是改善表格可读性和美观性的有效方法。通过 CSS 样式,可以轻松地将表格内容水平居中或垂直居中。
水平居中
要水平居中表格内容,请使用 text-center 类:
.table-centered { text-align: center; }
然后将其应用于
<table class="table-centered"> <tr> <th>头 1</th> <th>头 2</th> ... </tr> <tr> <td>数据 1</td> <td>数据 2</td> ... </tr> </table>
垂直居中
垂直居中表格内容需要更多步骤:
例如:
<table> <tr> <th> <div class="d-flex align-items-center" style="height: 50px;"> 头 1 </div> </th> ... </tr> ... </table>
要自定义高度,只需调整 style="height: 50px;" 中的值即可。
注意:
以上就是Bootstrap 表格内容居中:让数据更清晰的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号