-2

Let's say I have the following div:

<div>aaa, bbb- ccc. eee fff</div>

I was wondering if there is a css trick/property/function to apply a text-decoration: underline to the div on hover and have the underline appear only in the word where the cursor is? I know I can do it by wrapping each word in a span, but that doesn't seem very efficient.

MirrorMirror
  • 186
  • 8
  • 36
  • 70
  • 6
    I don't see any efficiency problem by wrapping the word in a `span`. Doing some CSS tricks (granted it existed for your case) it will be probably causing some issue in some browser version. I'd say play safe here. Nothing wrong with using a span tag for styling – NickHTTPS Jan 09 '19 at 09:01
  • https://stackoverflow.com/a/5688758/5385381 – ksav Jan 09 '19 at 09:13

1 Answers1

-1

You can split with the space and add span for each and every word. Then u can write text decoration to the span like below:

div:hover span {
  text-decoration: underline;
}
John_ny
  • 767
  • 12
  • 33