Change format of a specific word using CSS

喜欢而已 提交于 2021-02-17 03:18:45

问题


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:

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


回答1:


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;}

When it comes to jQuery:

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

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



来源:https://stackoverflow.com/questions/31811905/change-format-of-a-specific-word-using-css

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!