-1
<h2>hello world</h2>

Here, i want to styling first word "hello" without using any span or b tag or any JavaScript. just using style like h2:first-word{color:red}.

Is it possible? If possible how can i solve it?

Alex K.
  • 171,639
  • 30
  • 264
  • 288
Sonia Shurmi
  • 1
  • 1
  • 2

2 Answers2

0

You can't because there's no :first-word selector, only :first-letter and :first-line. You'll need insert span dynamically with JS if you don't control original HTML.

Dread Boy
  • 772
  • 6
  • 28
0

As far as i know it is not possible with pure css. There are some solutions with javascript.

Library: nthEverything Examples: Examples with ::first-word

MatKra
  • 157
  • 7