Last active
December 10, 2015 22:29
-
-
Save shinnn/4502883 to your computer and use it in GitHub Desktop.
Setting CSS sprite and :hover effect, in Sass
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
// background.jpg | |
// | |
// +------+------+ | |
// |#aaa |#aaa | | |
// | |:hover| | |
// +------+------+ | |
// |#bbb |#bbb | | |
// | |:hover| | |
// +------+------+ | |
// |#ccc |#ccc | | |
// | |:hover| | |
// +------+------+ | |
$currentSpriteY : 0px; | |
@mixin horizontalHover($elm, $singleWidth, $singleHeight){ | |
#{$elm}{ | |
background-position: 0px $currentSpriteY; | |
a:hover{ | |
background-position: -$singleWidth $currentSpriteY; | |
} | |
} | |
$currentSpriteY : $currentSpriteY - $singleHeight; | |
} | |
// Usage Example | |
@each $elm in "#aaa", "#bbb", "#ccc"{ | |
@include horizontalHover($elm, 80px, 40px); | |
} |
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
// background.jpg | |
// | |
// +------+------+------+ | |
// |#aaa |#bbb |#ccc | | |
// | | | | | |
// +------+------+------+ | |
// |#aaa |#bbb |#ccc | | |
// |:hover|:hover|:hover| | |
// +------+------+------+ | |
$currentSpriteX : 0px; | |
@mixin verticalHover($elm, $singleWidth, $singleHeight){ | |
#{$elm}{ | |
background-position: $currentSpriteY 0px; | |
a:hover{ | |
background-position: $currentSpriteY -$singleHeight; | |
} | |
} | |
$currentSpriteX : $currentSpriteX - $singleWidth; | |
} | |
// Usage Example | |
@each $elm in "#aaa", "#bbb", "#ccc"{ | |
@include verticalHover($elm, 40px, 80px); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment