Last active
March 8, 2016 09:31
-
-
Save LoicGoyet/623612833c3405560792 to your computer and use it in GitHub Desktop.
A sass function that returns a value to apply to a margin in order to vertically or horizontally align two elements.
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
/// Contexts | |
/// @author Loïc Goyet | |
/// @param {Unit} $element1 | |
/// @param {Unit} $element2 | |
/// @param {Bool} $invert | |
/// @warn the params $big-element & $small-element must share the same type of | |
/// unit | |
@function get-diff-to-align($element1, $element2, $invert: true) { | |
$big-element: if($element1 > $element2, $element1, $element2); | |
$small-element: if($element1 > $element2, $element2, $element1); | |
$diff: ($big-element - $small-element); // get the strict difference | |
$diff: round($diff / 2); // divide the diff by two for each side | |
$diff: if($invert, $diff * -1, $diff); | |
@return $diff; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment