Skip to content

Instantly share code, notes, and snippets.

@brianmcallister
Last active December 14, 2015 09:28
Show Gist options
  • Save brianmcallister/5065262 to your computer and use it in GitHub Desktop.
Save brianmcallister/5065262 to your computer and use it in GitHub Desktop.
Sass mixin to replace text with an svg background image. Requires the existence of a png fallback, which is what you should be doing anyway.
/*
Replace text with svg, use a png fallback.
https://gist.github.com/brianmcallister/5065262
$img - Image name to use, no extension.
*/
@mixin replace-text-with-svg($img) {
@extend %hide-text;
$png: '#{$img}.png';
@include size(image-width($png), image-height($png));
@include svg-background($img);
display: block;
margin-right: 10px;
}
/*
Set an svg background image with a png fallback.
$img - Image name without an extension.
*/
@mixin svg-background($img) {
$png: '#{$img}.png';
$svg: '#{$img}.svg';
background-image: image-url($png);
background-image: none, image-url($svg);
background-repeat: no-repeat;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment