I want to create a highlight effect that resembles a highlight made with a pen. i.e. it has wavy tops and bottoms and a rough start and end, like in this picture.
What's the best way to do this in CSS? Is there a way to do it without using background images? Also so that it works will line wraps.
Ideally the solution would take HTML like the below and make it look like the image.
<p>
<span class='green-highlight>So write with a combination of short, medium, and long sentences. Create a sound that pleases the reader's ear. </span>
<span class='pink-highlight'>Don't just write words. </span>
<span class='yellow-highlight'>Write music. </span
</p>
This answer is closer to the original question:
Credit to: https://codepen.io/laurenvast/pen/JmOaNd
Not using a background color..no.
Backgrounds extends to the edges of the element which are always rectangular (barring
border-radius
)In this case, a background image would probably the the optimal choice...BUT:
You can achieve a similar effect using multiple
text-shadow
s.A brief example.
It's just a matter of using as many shadows as you need to get the full effect you need,
for a hyper realistic pen highlighter:
Using CSS only, the closest you can get to your screenshot is something like this :
If that's not close enough, I'm afraid you have to use images.
If you're not limited to sub-HTML5 available tags, you could also use the
<mark>...</mark>
tag introduced in HTML5: