Skip to content

Instantly share code, notes, and snippets.

@azinasili
Last active April 9, 2018 16:52
Show Gist options
  • Save azinasili/71402a2b1008fa8c48a5 to your computer and use it in GitHub Desktop.
Save azinasili/71402a2b1008fa8c48a5 to your computer and use it in GitHub Desktop.
Easily add images + path
/// File path short cut for media
/// @param {string} $img-name - Name of media to append to path
/// @return {url} url to display media
/// @warn Warning when $img-name has no extention
/// @example scss
/// .foo {
/// background: image-url('kitten.jpg') no-repeat 0 0;
/// }
/// @example css
/// .foo {
/// background: url('path/to/kitten.jpg') no-repeat 0 0;
/// }
@function img-path($img-name) {
$img-path: 'path/to';
@if not str-index($img-name , '.') {
@warn '`#{$img-name}` needs a file extension like .jpg or .png';
@return false;
} @else {
@return url('#{$img-path}/#{$img-name}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment