Skip to content

Instantly share code, notes, and snippets.

@alkrauss48
Last active August 29, 2015 14:03
Show Gist options
  • Save alkrauss48/c995f6c4154c69a4ecfb to your computer and use it in GitHub Desktop.
Save alkrauss48/c995f6c4154c69a4ecfb to your computer and use it in GitHub Desktop.
Highlighting Text Around Each Character
// This entire file is optional. May be useful if using with a CMS where your users are
// entering in paragraphs, and you always want to highlight their paragraph text by default
$('p').wrapInner('<span class="highlight"></span>');
span.highlight {
background-color: rgba(0, 0, 0, .5);
box-shadow: 0.2em 0 0 rgba(0, 0, 0, .5),-0.2em 0 0 rgba(0, 0, 0, .5);
-moz-box-shadow: 0.2em 0 0 rgba(0, 0, 0, .5),-0.2em 0 0 rgba(0, 0, 0, .5);
-webkit-box-shadow: 0.3em 0 0 rgba(0, 0, 0, .5),-0.3em 0 0 rgba(0, 0, 0, .5);
}
/*
Optional: This gives IE8 translucent background support, but adds 2 translucent layers in IE9.
Does not affect IE10+. Your call.
*/
p {
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#80000000,endColorstr=#80000000);
}
<p>
<span class="highlight">
Let's assume this text is multiline.
Each line will highlight exactly to the end of the line,
and not like a big block
</span>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment