Guest User

Untitled

a guest
Jun 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. @mixin flex-content() {
  2. display: flex;
  3. justify-content: space-between;
  4. align-content: space-between;
  5. flex-flow: row wrap;
  6. align-items: baseline;
  7.  
  8. & > * { // all 1st gen children of flex-content should be inline-block
  9. display: inline-block
  10. }
  11. }
  12. /**
  13. * Creates the boilerplate CSS for flexbox columns if you follow the appropriate naming procedure.
  14. * @param {string} $base_col_class The base column class: ex: cols-2, the code will append the number (for two columns in this example, but you need to provide "cols" to it.
  15. * @param {integer} $min: 1 The number to begin iteration at
  16. * @param {integer} $max: 6 The number to end iteration at
  17. * @param {string} $s_breakout_width: '500px' The width where the columns will go 50% width
  18. * @param {string} $m_breakout_width: '1000px' The width where columns will go 33.3% width
  19. * @param {string} $l_breakout_width: '1200px' The width where columns will be divided as requested: ;
  20. * @param {string} $gutter: '20px' The spacing between elements. This uses flexbox justify-content: space-between
  21. * @return {string} A lot of CSS
  22. */
  23. @mixin columnsContainer($base_col_class, $min: 1, $max: 6, $s_breakout_width: '500px', $m_breakout_width: '1000px', $l_breakout_width: '1200px', $gutter: '20px') {
  24. @include flex-content();
  25.  
  26.  
  27. [class*="#{$base_col_class}"] {
  28. width: 100%;
  29. }
  30.  
  31. @media (min-width: $s_breakout_width) {
  32. @for $i from 2 through $max {
  33. @include _columnsWidths($base_col_class, $i, $gutter, 2);
  34. }
  35. }
  36.  
  37. @media (min-width: $m_breakout_width) {
  38. @for $i from 3 through $max {
  39. @include _columnsWidths($base_col_class, $i, $gutter, 3);
  40. }
  41. }
  42.  
  43. @media (min-width: $l_breakout_width) {
  44. @for $i from 4 through $max {
  45. @include _columnsWidths($base_col_class, $i, $gutter);
  46. }
  47. }
  48. }
  49.  
  50. /**
  51. * Basically called by columnsContainer mixin, but can be used anywhere I guess
  52. * Returns 100% divided by $i with the base class prepended
  53. *
  54. * Ex: @include columnsWidths('base',3)
  55. * will return .base-3 {width: calc(100% / 3);}
  56. */
  57. /**
  58. * Creates a CSS class for creating columns from some variables
  59. * @param {string} $base_class The "prepend" for the column class: ex: If your column class is "cols-2" provide "cols"
  60. * @param {integer} $i Iteration index
  61. * @param {string} $gutter The amount of space between columns
  62. * @param {integer} $override: null Pass in a number to override columns, used for responsive CSS. ex: pass in 2, will return 50% columns with gutters accounted for no matter what
  63. * @return {string} A bunch of CSS
  64. */
  65. @mixin _columnsWidths($base_class, $i, $gutter: 10px, $override: null) {
  66. @if($override) {
  67. .#{$base_class}-#{$i} {
  68. width: calc(100% / #{$override} - #{$gutter}) !important;
  69. }
  70. } @else {
  71. .#{$base_class}-#{$i} {
  72. width: calc(100% / #{$i} - #{$gutter}) !important;
  73. }
  74. }
  75.  
  76. }
  77.  
  78. // usage
  79.  
  80. .columns-container {
  81. @include columnsContainer('col');
  82. }
Add Comment
Please, Sign In to add comment