Skip to content

Instantly share code, notes, and snippets.

@verticalgrain
Last active September 21, 2017 15:51
Show Gist options
  • Save verticalgrain/d4061387d918ad8cd5ba49fa07317af8 to your computer and use it in GitHub Desktop.
Save verticalgrain/d4061387d918ad8cd5ba49fa07317af8 to your computer and use it in GitHub Desktop.
SASS / SCSS Cheatsheet
// Compile SASS or SCSS once from the command line
// sass --update sass-directory:css-directory
sass --update sass:css
// Watch SASS or SCSS directory from the command line
// sass --watch sass-directory:css-directory
sass --watch sass:css
// Watch SASS or SCSS file from the command line
sass --watch sass/sass-file.scss:css/css-file.css
// SASS function to encode SVG and use as background image:
@function svg-url($svg) {
$encoded: '';
$slice: 2000;
$index: 0;
$loops: ceil(str-length($svg)/$slice);
@for $i from 1 through $loops {
$chunk: str-slice($svg, $index, $index + $slice - 1);
$chunk: str-replace($chunk, '"', '\'');
$chunk: str-replace($chunk, '<', '%3C');
$chunk: str-replace($chunk, '>', '%3E');
$chunk: str-replace($chunk, '&', '%26');
$chunk: str-replace($chunk, '#', '%23');
$encoded: #{$encoded}#{$chunk};
$index: $index + $slice;
}
@return url("data:image/svg+xml,#{$encoded}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment