使用CSS更改特定单词的格式 [英] Change format of a specific word using CSS

查看:56
本文介绍了使用CSS更改特定单词的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文本可以来自不同的来源.收到文字后,它将显示在网站上.从此文本中,我需要使用CSS更改特定单词的格式.在以下示例中,必须更改 database 单词:

Text can come form different source. After getting text it will display on site. From this text I need to change format of a specific word using CSS. In following example database word have to change:

这很容易由JavaScript完成 JSFiddle ,但是我需要CSS不是通过JavaScript.有什么主意吗?

It is easily done by JavaScript JSFiddle but I need it by CSS not by JavaScript. Any idea?

推荐答案

您不能使用CSS选择内容,但可以使用jQuery选择内容.您可以在跨度中包装数据库",然后使用CSS对其进行样式设置.例如:

You cannot select content with CSS, but with jQuery you can. You could wrap "database" in span and then use CSS to style it. For example:

HTML:

<p>A <span class="database">database</span> is a collection of information. In one view <span class="database">database</span> can be classified.</p>

CSS:

.database {color: red;}

关于jQuery:

$( "p:contains('database')" ).css( "color", "red" );

这可能是最简单的解决方案,但我个人不喜欢它.

That would probably be the easiest solution, but I personally don't like it.

这篇关于使用CSS更改特定单词的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆