user1364363
user1364363

Reputation: 49

In html or css how can I set a specific word to always be a certain colour?

I'm using html & css. I want a certain word to always be set to the colour red. I can use the span tags to set one word to red, but I don't want to have to type this out for every occurance of the word, is there kind of like a "global" way of doing this?

Thanks.

Lets say the word is "cat" btw.

Upvotes: 1

Views: 529

Answers (2)

Johannes Klauß
Johannes Klauß

Reputation: 11020

I think you need to do this either manually or with Javascript using regular expressions. A good jQuery plugin is http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html

Upvotes: 0

Quentin
Quentin

Reputation: 943142

You can't. CSS styles elements, not arbitrary bits of text.

You could programatically modify the document (either server side or with client side JS) to add additional markup (e.g. <span class="cat"> and </span>) around the words you care about (being careful to only alter words in regular text nodes and not in CDATA sections or attribute values.

Upvotes: 1

Related Questions