Created
March 17, 2014 11:10
-
-
Save dalgard/9597500 to your computer and use it in GitHub Desktop.
Use placeholder selectors for icons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use embedded fonts | |
@font-face { | |
font-family: 'icons'; | |
font-weight: normal; | |
font-style: normal; | |
src: | |
url(data:application/x-font-ttf;charset=utf-8;base64,...) format('truetype'), | |
url(data:application/font-woff;charset=utf-8;base64,...) format('woff'); | |
} | |
// Map of names and character codes | |
$icons: ( | |
('facebook', '\e601') | |
('linkedin', '\e602') | |
('twitter', '\e603') | |
('youtube', '\e604') | |
('checkmark', '\e61d') | |
('mail', '\e600') | |
// ... | |
); | |
// Empty list | |
$all-selectors: (); | |
// Loop each icon and output selectors | |
@each $icon in $icons { | |
$selectors: ( | |
// Uncomment to enable data-icon attributes | |
/* | |
unquote("[data-icon='#{nth($icon, 1)}']:before"), | |
unquote("[data-icon-after='#{nth($icon, 1)}']:after"), | |
*/ | |
unquote("%icon-#{nth($icon, 1)}:before"), | |
unquote("%icon-#{nth($icon, 1)}-after:after") | |
); | |
// Output the actual selectors for each character code | |
#{$selectors} { content: nth($icon, 2); } | |
// Add icon to list of all selectors | |
$all-selectors: join($all-selectors, $selectors, comma); | |
} | |
// Icon styles for all selectors | |
#{$all-selectors} { | |
display: inline-block; | |
text-transform: none; | |
font-family: 'icons'; | |
font-style: normal; | |
font-weight: normal; | |
font-variant: normal; | |
line-height: 1; | |
speak: none; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
} | |
// Use this mixin to add an icon to an element | |
// (only the styling of the :before/:after element is affected) | |
@mixin icon($name, $placement: before) { | |
&:#{$placement} { | |
@if $placement == after { @extend %icon-#{$name}-after:after; } | |
@else { @extend %icon-#{$name}:before; } | |
@content; | |
} | |
} |
Author
dalgard
commented
Mar 17, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment