2

I want to create a feature where users can annotate different subsections of a text. When an annotation has been made an underline will show under that part of the text. How could I create this effect with HTML/CSS?

Underlining effect

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Peter R
  • 3,185
  • 23
  • 43

2 Answers2

5

You can achieve this kind of underlining effect with linear gradients :

span {
    line-height: 20px;
    background: linear-gradient(0deg, green 1px, white 1px, transparent 1px);
    background-position: 0 100%;
}
.two {
    line-height: 24px;
    padding-bottom: 4px;
}
.three {
    line-height: 28px;
    padding-bottom: 8px;
}
<p><span class="one">Lorem ipsum <span class="two">dolor</span> sit amet,</span>consectetur adipiscing elit. <span class="one">Maecenas <span class="two"><span class="three">finibus</span></span></span><span class="two"> aliquam eros eget accumsan.Pellentesque quis <span class="three">diam lacus.</span></span></p>

Note that I didn't insert the vendor prefixes for the linear gradient

web-tiki
  • 99,765
  • 32
  • 217
  • 249
0

You cannot do that directly with HTML and CSS.

You can do that in a modern browser writing custom code and creating a custom Canvas/SVG solution. But that's a very hard to do work. Try looking for some graphics library that can help you do it.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
JotaBe
  • 38,030
  • 8
  • 98
  • 117