gpt4 book ai didi

css - 如何将文本与背景图像居中

转载 作者:行者123 更新时间:2023-11-28 08:38:02 25 4
gpt4 key购买 nike

我真的很想做这样的事情......当我在左边有带有图标的文本时:

enter image description here

我尝试(未成功)按照以下方式做一些事情:

    <a href="#" class="icon">Text centered vertically in relation 
to the background image</a>

CSS

a.icon {
background: url(image.png) 0 50%;
margin-top: -5%;
min-height: the-height-of-my-image-plus-the-negative-margin;
}

最佳答案

line-height 设置为与 a 标签的 height 相同。像这样:

a.icon {
background: url(image.png) 0 50%;
margin-top: -5%;
height:40px;
line-height:40px;
text-align:center;
}

关于css - 如何将文本与背景图像居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9587879/

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