Last active
August 29, 2015 14:27
-
-
Save Razenbull/e4264d273520be07a50f to your computer and use it in GitHub Desktop.
Mixin to align vertically an element relative to its first positioned parent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Mixin to align vertically an element relative to its first positioned parent | |
* | |
* @params $position-type | |
* @params $align | |
* | |
* @use @include vertical-align; | |
* or @include vertical-align($position-type: absolute, $align: bottom); | |
* to override defaults | |
* | |
*/ | |
@mixin vertical-align($position-type: relative, $align: middle) { | |
$translate: 0% !default; | |
$y: 0% !default; | |
position: $position-type; | |
@if $align == middle { | |
$translate: 50%; | |
$y: 50%; | |
} @else if $align == bottom { | |
$translate: 100%; | |
$y: 100%; | |
} @else if $align == over-the-top { | |
$translate: 100%; | |
$y: 0%; | |
} @else { | |
@if $position-type != relative and $position-type != absolute and $position-type != static { | |
@warn 'unknown $position-type: ' + $position-type; | |
} @else if $align != over-the-top and $align != bottom and $align != middle { | |
@warn 'unknown $align: ' + $align; | |
} | |
} | |
@include transform(translateY(-$translate)); | |
top: $y; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment