Created
December 22, 2016 20:17
-
-
Save mattdanielbrown/a1c4f54508ca4c40252ba525d0d7b1a9 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Quickly arrange child elements using flex. | |
* | |
* @param($direction, $distribution) | |
* | |
* $direction: Sets the axis the items are aligned to. | |
* [v, vertical, c, column | h, horizontal, r, row] (!optional - default = v) | |
* ... amounts to `flex-direction:` ... | |
* | |
* $distribution: Sets how items are arranged along main axis. | |
* [c, center | sa, a, space-around | sb, b, space-between] (!optional - default = c) | |
* ... sets the `justify-content:` property... | |
* | |
* [Example Usage:] | |
* | |
* .class { | |
* @include flexArrange(vertical, sa); | |
* } | |
* | |
* ---OUTPUTS TO: | |
* | |
* .class { | |
* display: flex; | |
* align-items: center; | |
* align-content: center; | |
* flex-direction: column; | |
* justify-content: space-around; | |
* } | |
*/ | |
@mixin flexArrange($direction: v, $distribution: c) { | |
// set the constants | |
display: flex; | |
align-items: center; | |
align-content: center; | |
// Set direction | |
@if($direction==v or $direction=='vertical' or $direction==column) { | |
flex-direction: column; | |
} | |
@else { | |
flex-direction: row; | |
} | |
// Set content distribution | |
@if($distribution==c or $distribution==center) { | |
justify-content: center; | |
} | |
@else if($distribution==s or $distribution==sa or $distribution==space-around) { | |
justify-content: space-around; | |
} | |
@else { | |
justify-content: space-between; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment