gpt4 book ai didi

html - 在中间的图像上添加文本

转载 作者:行者123 更新时间:2023-11-27 22:34:56 24 4
gpt4 key购买 nike

我想在中间的图像上添加一些文本。我使用这段代码:

<div style="background-image: url(../images/game-hearts-icon.png); height: 64px; width: 64px; text-align: center; vertical-align:middle;">text</div> 

我想让文字在心的中间。但它只是出现在顶部居中。垂直对齐似乎不起作用。我究竟做错了什么?任何帮助表示赞赏!

最佳答案

设置 line-height 等于你的 div 的高度:

<div style="background-image: url(../images/game-hearts-icon.png); height: 64px; width: 64px; text-align: center; line-height: 64px;">text</div>

更好的是,不要使用内联样式:

HTML

<div class="game-hearts-icon">text</div>

CSS

.game-hearts-icon {
background: transparent url(../images/game-hearts-icon.png) scroll 0 0 no-repeat;
height: 64px;
line-height: 64px;
text-align: center;
width: 64px;
}

关于html - 在中间的图像上添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14575338/

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