gpt4 book ai didi

CSS使背景图像使用字体字符

转载 作者:行者123 更新时间:2023-12-02 20:00:39 24 4
gpt4 key购买 nike

我想使用字体字符(例如来自 font-awesome)作为输入元素的背景图像。

<style>
#id {
background-image: content('\f2d3'); /* content instead of url() */
background-position: right center;
}
</style>

<input id="test" />

我的猜测是,我要么将 Angular 色保存为图像,要么使用伪元素 :after 以及 内容 和足够的定位来实现此目的。只是想看看是否有更好的解决方案。就像是否可以访问 SVG 中的字符并使用内联 SVG 作为内容?

更新:

我用 SVG 制作了一个部分解决方案(请参阅 https://jsfiddle.net/92h52e65/4/ ),但仍然存在使用正确字体的问题。

<style>
#input1 {
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="30px" height="20px"><text x="5" y="15" font-family="FontAwesome">x&#xf2d3;</text></svg>');
background-position: right center;
background-repeat: no-repeat no-repeat;
}
</style>

<input id="input1" placeholder="insert some text here" size="30" required />

为了在 IE 和 FF 中工作,我必须使用 base64 编码而不是 utf8。我在这里留下了 utf8 以使其更具可读性。

最佳答案

您需要使用background-image有什么特殊原因吗?

如果没有,你可以这样做:

.input1wrap::after {
font-family: FontAwesome;
content: '\f2d3';
margin-left: -1.5em;
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<span class="input1wrap">
<input id="input1" placeholder="insert some text here" size="30" required />
</span>

关于CSS使背景图像使用字体字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40425605/

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