Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yowainwright/0d96258c1bf1bac3fb652d64bc556579 to your computer and use it in GitHub Desktop.
Save yowainwright/0d96258c1bf1bac3fb652d64bc556579 to your computer and use it in GitHub Desktop.
Sass Mixin for Optimal Text Underlining 🤓

This Gist contains a SCSS Mixin for Optimal Text Underlining

This SCSS Mixin changes the text underline color or its location relative to the text it underlines.

A Pen by Jeff Wainwright on CodePen.

License.

$color-theme-default: red;
// link underlines
@mixin text-underline(
$background: white,
$underline: $color-theme-default,
$position: 85%,
$fontsize: 1rem
) {
// $width = 1/10 the fontsize
$width: $fontsize * .1;
color: inherit;
text-decoration: none;
background:
linear-gradient($background, $background),
linear-gradient($background, $background),
linear-gradient($underline, $underline);
// this sets up the size of the bottom border
background-size: #{$width / 2} $width;
background-repeat: no-repeat, no-repeat, repeat-x;
// this create all of the text shadows needed to create a stroke around the text
text-shadow:
$width $width $background,
$width 0 $background,
0 $width $background,
-#{$width} -#{$width} $background,
-#{$width} 0 $background,
0 -#{$width} $background;
// this sets up the location of the bottom border
background-position: 0 $position, 100% $position;
}
body {
margin: 0;
padding: 2rem;
}
span {
font-size: 2rem;
@include text-underline(white, red, 100%, 2rem);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment