gpt4 book ai didi

html - Bootstrap 在 div 中垂直居中文本

转载 作者:太空宇宙 更新时间:2023-11-03 23:37:46 24 4
gpt4 key购买 nike

我想在 div 中垂直居中放置文本,但无法正常工作。

代码:

<div>
<h3><i class="fa fa-cloud fa fa-3x"></i> Text</h3>
</div>

enter image description here

有人有解决办法吗?我尝试了很多可能性,但似乎都不起作用。

最佳答案

这就是我最终将云字形居中的方式:

CSS

<style>
h3 {
line-height: 48px;
}
span {
vertical-align: middle;
}
.glyphicon-cloud {
font-size: 48px;
}
</style>

HTML

<div>
<h3>
<span class="glyphicon glyphicon-cloud"></span>
Text
</h3>
</div>

我设置了 line-heightfont-size字形图标和 h348px 相同的值然后应用vertical-align: middle;<span>包含字形图标。

编辑:

取自Bootstrap API website , 你不应该将类与 <span> 混在一起,正如你似乎拥有的:

Don't mix with other components Icon classes cannot be directly combined with other components. They should not be used along with other classes on the same element. Instead, add a nested and apply the icon classes to the <span>.

关于html - Bootstrap 在 div 中垂直居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23617970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com