Skip to content

Instantly share code, notes, and snippets.

@jednano
Last active August 29, 2015 13:58
Show Gist options
  • Save jednano/10022370 to your computer and use it in GitHub Desktop.
Save jednano/10022370 to your computer and use it in GitHub Desktop.
Sass mixins
// ----
// Sass (v3.3.4)
// Compass (v1.0.0.alpha.18)
// ----
@mixin app-font($name, $weight: normal, $style: normal) {
$font-files:
inline-font-files(
'#{$name}.woff', woff
),
font-files(
'#{$name}.ttf', truetype,
'#{$name}.svg#font', svg
);
@include font-face($name, $font-files, '#{$name}.eot', $weight, $style);
}
@mixin background($color: null, $image: null, $repeat: null, $attachment: null, $position: null, $size: null) {
background: $color $image $repeat $attachment $position;
@if $size {
@include background-size($size);
}
}
@mixin center-by($width: 0, $height: 0) {
@if $width == 0 or $height == 0 {
@warn "center-by() requires width or height above zero.";
}
display: block;
position: absolute;
@if $width > 0 {
left: 50%;
margin-left: $width / -2;
}
@if $height > 0 {
top: 50%;
margin-top: $height / -2;
}
}
@mixin font($weight: null, $style: null, $variant: null, $size: null, $line-height: null, $family: null) {
$font: $weight $style $variant;
@if $size and $line-height {
$font: $font $size/#{$line-height};
}
@else if $size {
$font: $font $size;
}
font: $font $family;
@if $line-height and not $size {
line-height: $line-height;
}
}
// example: @include translucent-bg(@includeSmoke, 0.7);
@mixin translucent-bg($color, $opacity) {
background-color: $color;
background-color: transparentize($color, 1 - $opacity);
}
// example: @include translucent-bg(@includeSmoke, 0.7);
@mixin translucent-text($color, $opacity) {
color: $color;
color: transparentize($color, 1 - $opacity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment