Skip to content

Instantly share code, notes, and snippets.

@unti1x
Last active October 26, 2015 08:18
Show Gist options
  • Save unti1x/0c1612e15c998fef50eb to your computer and use it in GitHub Desktop.
Save unti1x/0c1612e15c998fef50eb to your computer and use it in GitHub Desktop.
Generate sprite-map with custom class names and styles using Compass
// generate sprite from dir, using specified prefix, base class and styles
@mixin spritez($path, $prefix, $base-class) {
$sprite-map: sprite-map($path, $layout: smart);
$sprite-names: sprite-names($sprite-map);
#{$base-class} {
background-image: sprite-url($sprite-map);
background-repeat: no-repeat;
display: inline-block;
@content;
}
@each $name in $sprite-names {
.#{$prefix}-#{$name} {
background-position: sprite-position($sprite-map, $name);
@include sprite-dimensions($sprite-map, $name);
}
}
}
// usage
$social-sprite-base-class: ".icon-social";
@include spritez("icons/social/*.png", "icon-social", $social-sprite-base-class) {
width: 26px;
vertical-align: middle;
height: 26px;
margin-right: 6px;
}
.icon-social {
background-image: url('/images/sprites/icons/social-sacd010fbfc.png');
background-repeat: no-repeat;
display: inline-block;
width: 26px;
vertical-align: middle;
height: 26px;
margin-right: 6px; }
.icon-social-fb {
background-position: 0 0;
height: 26px;
width: 26px; }
.icon-social-googleplus {
background-position: 0 -26px;
height: 26px;
width: 26px; }
.icon-social-inst {
background-position: 0 -52px;
height: 26px;
width: 26px; }
.icon-social-ok {
background-position: 0 -78px;
height: 26px;
width: 26px; }
.icon-social-twitter {
background-position: 0 -104px;
height: 26px;
width: 26px; }
.icon-social-vk {
background-position: 0 -130px;
height: 26px;
width: 26px; }
.icon-social-yt {
background-position: 0 -156px;
height: 26px;
width: 26px; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment