Skip to content

Instantly share code, notes, and snippets.

@jhafner
Created September 3, 2013 15:16
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 jhafner/6425280 to your computer and use it in GitHub Desktop.
Save jhafner/6425280 to your computer and use it in GitHub Desktop.
// For adding icons to elements using CSS pseudo-elements
// Source: http://jaydenseric.dev/blog/fun-with-sass-and-font-icons
@mixin icon($position: 'before', $styles: true, $icon: false) {
// Either a :before or :after pseudo-element, defaulting to :before
&:#{$position} {
@if $icon {
// Icon has been specified
content: match($icons, $icon);
}
@if $styles {
// Suportive icon styles have been specified
font-family: 'Icons';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
}
// Include any extra rules supplied for the pseudo-element
@content;
}
}
//Usage
a[href^="mailto"] {
@include icon('before', true, 'email') {
margin-right: 20px;
color: blue;
}
}
//Compiles to:
a[href^="mailto"]:before {
content: 'e005';
font-family: 'Icons';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
-webkit-font-smoothing: antialiased;
margin-right: 20px;
color: blue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment