Skip to content

Instantly share code, notes, and snippets.

@joemcgill
Created November 5, 2012 22:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemcgill/4020718 to your computer and use it in GitHub Desktop.
Save joemcgill/4020718 to your computer and use it in GitHub Desktop.
Inline Text Background (CSS only)
/*
* Class for defining text with background on text only and not the whole block.
* May require definition of html element (i.e. p.textbg) in order to make line-height
* and font-size work.
*/
.textbg {
padding:5px 0; /* top and bottom padding */
color:#fff;
font-size: 24px;
line-height: 48px; /* use this to create horizontal space between lines */
display: inline;
background-color:red;
box-shadow: 10px 0 0 0 red, -10px 0 0 0 red; /* left/right padding (IE8 needs fallback) */
left:10px; /* match px of box-shadow above to align text */
position: relative;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment