Skip to content

Instantly share code, notes, and snippets.

@chadclark
Last active December 16, 2015 21:20
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadclark/5498661 to your computer and use it in GitHub Desktop.
Save chadclark/5498661 to your computer and use it in GitHub Desktop.
A .scss mixin that makes it easy to include a .png fallback for .svg background images when using Modernizr.
// ---------------------------------------------------------------------------------
// CSS Image Paths
// ---------------------------------------------------------------------------------
$bg-img-path: '/path/to/images/'; // Base Path for BG Layout Images
// ---------------------------------------------------------------------------------
// Modernizr SVG Fallback
// Inspired by https://forrst.com/posts/Sass_Compass_Mixin_for_SVG_Background_Image_Fall-dWn
// ---------------------------------------------------------------------------------
@mixin no-svg { .no-svg & { @content } }
@mixin svg-bkgd($filename, $pos-x: '0', $pos-y: '0', $repeat: 'no-repeat', $extension: '.png') {
background: transparent url($bg-img-path + $filename + '.svg') $pos-x $pos-y $repeat;
@include no-svg { background: transparent url($bg-img-path + $filename + $extension) $pos-x $pos-y $repeat; }
}
// ---------------------------------------------------------------------------------
// How to Use
// ---------------------------------------------------------------------------------
@include svg-bkgd(filename, right, center, no-repeat);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment