My application is that it is some online document to which user can annotate and underline the text for reference. Now this can be done by multiple users, hence need to have dif
All the answers are not complete so far.
Your main requirement is:
Application is that it is some online document to which user can annotate and underline the text for reference. Now this can be done by multiple users, hence need to have different colors for each underline.
According to the above quote, it is required to have all words, white spaces or even letters kept as a separated inline element for instance .
Why?
It will be definitely easier to handle annotations when every element will be separated, especially when you want to use responsive layout.
Let's take a look at the example:
Fiddle: https://jsfiddle.net/00w5f0c9/1/