Skip to content

Instantly share code, notes, and snippets.

@manuhabitela
Last active December 23, 2015 10:19
Show Gist options
  • Save manuhabitela/6620840 to your computer and use it in GitHub Desktop.
Save manuhabitela/6620840 to your computer and use it in GitHub Desktop.
Sass position mixin that uses transforms (translateX/translateY) when available
/** Sass mixins to position stuff with transforms when they're available with Modernizr and with usual position values otherwise
*
* instead of writing `bottom: 7px`, just write `@include bottom(7px)`
**/
@mixin __position($pos, $value) {
html.no-csstransforms & {
#{$pos}: $value;
}
html.csstransforms & {
@if $pos == right or $pos == bottom {
$value: -1*$value;
}
@if $pos == left or $pos == right {
@include transform(translateX(#{$value}));
}
@if $pos == top or $pos == bottom {
@include transform(translateY(#{$value}));
}
}
}
@mixin top($value) { @include __position(top, $value); }
@mixin bottom($value) { @include __position(bottom, $value); }
@mixin left($value) { @include __position(left, $value); }
@mixin right($value) { @include __position(right, $value); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment