user201535
user201535

Reputation: 107

How to change the font color of specific words in CSS?

Giving a structure similar to

adjoasdouhaosdh asdj oaushdo hello

i apologize for the random words, hello

I guess my question would be is there an easier way to make the 'hello's a different color? Sorry if this is confusing

Upvotes: 0

Views: 3393

Answers (2)

Michael Benjamin
Michael Benjamin

Reputation: 371231

HTML

<p>adjoasdouhaosdh asdj oaushdo <span>hello</span></p>

<p>i apologize for the random words, <span>hello</span></p>

CSS

p > span { 
    color: red;
    font-weight: bold;
}

DEMO: http://jsfiddle.net/uq6rswpk/


In reference to your comment asking how to select a <p> element among a group of <p> siblings, you can use the :nth-child pseudo-class.

p:nth-child(2) { ... }

Upvotes: 2

Hacktisch
Hacktisch

Reputation: 1514

So you don't want to wrap tags around the 'hello's manually. There is no way then to do this in css. The only way then is to use javascript to search for these words and wrap them inside tags.

But I would recommend to do this on the server side instead of client side, so in a preprocessing function

Upvotes: 1

Related Questions