Skip to content

Instantly share code, notes, and snippets.

@daneden
Created July 18, 2014 17:48
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daneden/e171f69ebfad62368f32 to your computer and use it in GitHub Desktop.
Save daneden/e171f69ebfad62368f32 to your computer and use it in GitHub Desktop.
// Not shown here is the Grunt task that takes source SVGs, creates PNGs (later optimised by imageoptim) and minified SVGs
@mixin bg-image($image, $size: 16px, $repeat: no-repeat, $position: center) {
// SVG backgrounds with PNG fallback
// All browsers that support multiple backgrounds also support SVGs. Woohoo!
background-image: image-url("#{$image}.png");
// inline-image requires Compass
background-image: inline-image("#{$image}.min.svg"), none;
background-size: $size;
background-repeat: $repeat;
background-position: $position;
}
// Usage:
.site__logo {
@include bg-image("logo", 36px auto, no-repeat, left center);
}
/*
** Output:
**
** .site__logo {
** background-image: url("logo.png");
** background-image: url("data:image/svg+xml;base64, PHJLK...), none;
** background-size: 36px auto;
** background-repeat: no-repeat;
** background-position: left center;
** }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment