williamchanter
williamchanter

Reputation: 169

Target certain words with CSS?

This is kind of a theory question but I wonder whether it is possible or not.

So if you have a div with some content like...

<div>£100.00 - BUY</div>

Can you then target "£100.00" without targeting the rest?

So you can increase the font size of £100.00?

Upvotes: 3

Views: 8294

Answers (3)

Josh Crozier
Josh Crozier

Reputation: 241248

You could target it by wrapping it in a span element:

jsFiddle example

<div><span class="price">$100.00</span> - BUY</div

Upvotes: 4

Afzaal Ahmad Zeeshan
Afzaal Ahmad Zeeshan

Reputation: 15860

You can use this

<div><span id="price">£100.00</span> - BUY</div>

CSS

#price {  
 font-size: 2em; // double of the current font  
}  

div {  
font-size: inherit; // get the font-size from the browser or the document.  
}

This will give the div a default font-size but the span with id price will have twice the font-size as the div.

Upvotes: 2

Alnitak
Alnitak

Reputation: 340055

No, that can't be done without wrapping the desired text in another element, typically a <span>.

Upvotes: 5

Related Questions