问题
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