Created
January 18, 2013 13:50
-
-
Save gavinmcfarland/4564657 to your computer and use it in GitHub Desktop.
A mixin for SASS that uses background sizing to help you create icons from a sprite.
This file contains hidden or 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
| @mixin icon($index, $size) { | |
| line-height: 1; | |
| vertical-align: middle; | |
| &:before { | |
| // Manually define the icon set */ | |
| $columns: 5; // Number of icons going across | |
| background-image: url(icons/large/sprite.png); | |
| background-size: $columns * 100%; | |
| // Size icon will be displayed */ | |
| width: #{$size}px; | |
| height: #{$size}px; | |
| // Position background-image based on number of icons in sprite */ | |
| background-position: #{(100/($columns - 1)*($index - 1))}% 0; | |
| // Set position to inline */ | |
| content: ""; | |
| margin-right: #{$size/4}px; | |
| display: inline-block; | |
| line-height: #{$size}px; | |
| vertical-align: middle; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment