Advertisement
T99

Flexbox Mixin

T99
Sep 17th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 3.29 KB | None | 0 0
  1. /*
  2.  * Example: @include flex-container("down", "top", "left", "nowrap");
  3.  *
  4.  * 1st Arg:     -- Main Axis --
  5.  *  - "down":   Defines the main axis as vertical.
  6.  *  - "across": Defines the main axis as horizontal.
  7.  *
  8.  * 2nd Arg:     -- Vertical Centering --
  9.  *  - "top":    Aligns items in the flexbox to the upper edge.
  10.  *  - "center": Vertically centers items in the flexbox.
  11.  *  - "bottom": Aligns items in the flexbox to the lower edge.
  12.  *
  13.  * 3rd Arg:     -- Horizontal Centering --
  14.  *  - "left":   Aligns items in the flexbox to the left edge.
  15.  *  - "center": Horizontally centers items in the flexbox.
  16.  *  - "right":  Aligns items in the flexbox to the right edge.
  17.  *
  18.  * 4th Arg:     -- Wrapping --
  19.  *  - "nowrap": Does not wrap items to new columns (vertical flexbox) or new rows (horizontal flexbox).
  20.  *  - "wrap":   Wraps items to new columns (vertical flexbox) or new rows (horizontal flexbox).
  21.  */
  22. @mixin flex-container($direction, $verticalCentering, $horizontalCentering, $wrapping) {
  23.    
  24.     display: flex;
  25.    
  26.     @if($direction == "down") {
  27.        
  28.         flex-direction: column;
  29.        
  30.         @if($verticalCentering == "top") {
  31.            
  32.             justify-content: flex-start;
  33.            
  34.         } @else if($verticalCentering == "bottom") {
  35.            
  36.             justify-content: flex-end;
  37.            
  38.         } @else if ($verticalCentering == "center"){
  39.            
  40.             justify-content: center;
  41.            
  42.         } @else {
  43.            
  44.             @error "The 'flex-container' mix-in recieved an invalid parameter for '$verticalCentering', of '" + $verticalCentering + "', where it should have recieved 'top', 'bottom', or 'center'."
  45.            
  46.         }
  47.        
  48.         @if($horizontalCentering == "left") {
  49.            
  50.             align-items: flex-start;
  51.            
  52.         } @else if($horizontalCentering == "right") {
  53.            
  54.             align-items: flex-end;
  55.            
  56.         } @else if ($horizontalCentering == "center") {
  57.            
  58.             align-items: center;
  59.            
  60.         } @else {
  61.            
  62.             @error "The 'flex-container' mix-in recieved an invalid parameter for '$horizontalCentering', of '" + $horizontalCentering + "', where it should have recieved 'left', 'right', or 'center'."
  63.            
  64.         }
  65.        
  66.     } @else {
  67.        
  68.         flex-direction: row;
  69.        
  70.         @if($verticalCentering == "top") {
  71.            
  72.             align-items: flex-start;
  73.            
  74.         } @else if($verticalCentering == "bottom") {
  75.            
  76.             align-items: flex-end;
  77.            
  78.         } @else if ($verticalCentering == "center") {
  79.            
  80.             align-items: center;
  81.            
  82.         } @else {
  83.            
  84.             @error "The 'flex-container' mix-in recieved an invalid parameter for '$verticalCentering', of '" + $verticalCentering + "', where it should have recieved 'top', 'bottom', or 'center'."
  85.            
  86.         }
  87.        
  88.         @if($horizontalCentering == "left") {
  89.            
  90.             justify-content: flex-start;
  91.            
  92.         } @else if($horizontalCentering == "right") {
  93.            
  94.             justify-content: flex-end;
  95.            
  96.         } @else if ($horizontalCentering == "center") {
  97.            
  98.             justify-content: center;
  99.            
  100.         } @else {
  101.            
  102.             @error "The 'flex-container' mix-in recieved an invalid parameter for '$horizontalCentering', of '" + $horizontalCentering + "', where it should have recieved 'left', 'right', or 'center'."
  103.            
  104.         }
  105.        
  106.     }
  107.    
  108.     @if($wrapping == "wrap") {
  109.        
  110.         flex-wrap: wrap;
  111.        
  112.     } @else if ($wrapping == "nowrap") {
  113.        
  114.         flex-wrap: nowrap;
  115.        
  116.     } @else {
  117.        
  118.         @error "The 'flex-container' mix-in recieved an invalid parameter for '$wrapping', of '" + $wrapping + "', where it should have recieved 'wrap' or 'nowrap'."
  119.        
  120.     }
  121.    
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement