Skip to content

Instantly share code, notes, and snippets.

@yowainwright
Created November 30, 2017 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yowainwright/3be159d7211578627fa2a70224956587 to your computer and use it in GitHub Desktop.
Save yowainwright/3be159d7211578627fa2a70224956587 to your computer and use it in GitHub Desktop.
Useful SCSS Positioning Mixins
// vertically center
@mixin vertical-align($position: relative) {
position: $position;
top: 50%;
transform: translateY(-50%);
}
// Example usage: @include vertical-align;
// horizontally align
@mixin horizontal-align($position: relative) {
position: $position;
left: 50%;
transform: translateX(-50%);
}
// Example usage: @include horizontal-align;
// middle align (vertically & horizontally center)
@mixin middle-align($position: absolute) {
left: 50%;
position: $position;
top: 50%;
transform: translate(-50%, -50%);
}
// Example usage: @include middle-align;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment