gpt4 book ai didi

Css 背景文本颜色空间

转载 作者:行者123 更新时间:2023-11-28 18:22:06 25 4
gpt4 key购买 nike

我想在我的 div 中为我的文本添加背景色,但我只想在文本而不是空格上使用背景色...我该怎么做。有什么技巧吗?

<div class="for">Maintenance Reliability Comfor</div>

display: inline-block;
padding: 5px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin-bottom: 5px;
background-color: rgb(98, 206, 38);

http://jsfiddle.net/PfLkD/

最佳答案

您可以尝试使用 jQuery:

$('div').each(function() {

var words = $(this).text().split(' ');

$(this).empty().html(function() {

for (i = 0; i < words.length; i++) {
if (i == 0) {
$(this).append('<span>' + words[i] + '</span>');
} else {
$(this).append(' <span>' + words[i] + '</span>');
}
}

});

});

这段代码放在<span>标记在每个单词周围,因此您无需一个一个地写。

然后……:.for span {background:red;}

A working example .

关于Css 背景文本颜色空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16598485/

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