Reputation: 31998
Assuming I have this HTML code:
<p>Hello world</p>
Is there a way, with CSS only, without modifying the actual HTML, to change the style of the w
in the Hello world
text? (let's say, paint it green)
Upvotes: 0
Views: 1878
Reputation: 273031
If the font-size
and the font-family
are known, you can do this using gradient. Simply adjust the value so that only the w
is colored
p {
font-size: 30px;
background:
linear-gradient(to right, black 50%, green 50%,green 67%,#000 67%);
display: inline-block;
background-clip: text;
color: transparent;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<p>Hello world</p>
Upvotes: 1
Reputation: 60563
No is not possible (unless it is the first letter), the workaround is using a span
around the w
and then style it
p span {
color: lightgreen
}
div::first-letter {
color: red
}
<p>Hello <span>w</span>orld</p>
<div>Hello world</div>
Upvotes: 2