_grid-flex.scss 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // http://www.thesassway.com/intermediate/simple-grid-mixins
  2. @mixin row() {
  3. display:flex;
  4. flex-direction: row;
  5. flex-wrap: nowrap;
  6. align-items: stretch;
  7. @media only screen and (max-width: $small-bp) {
  8. flex-wrap:wrap;
  9. }
  10. }
  11. .row{
  12. @include row;
  13. }
  14. .row-rl{
  15. @include row;
  16. }
  17. // small
  18. .small-row {
  19. @media only screen and (max-width: $small-bp) {
  20. @include row;
  21. }
  22. }
  23. // medium
  24. .med-row {
  25. @media only screen and (min-width: $small-bp+1) and (max-width: $med-bp) {
  26. @include row;
  27. }
  28. }
  29. // large
  30. .large-row {
  31. @media only screen and (min-width: $med-bp+1) {
  32. @include row;
  33. }
  34. }
  35. %col-reset {
  36. box-sizing: border-box;
  37. }
  38. @mixin col($col, $offset: 0, $sum: $default_sum, $gap: $default_gap, $align: top) {
  39. @extend %col-reset;
  40. padding-left: $gap*$offset;
  41. @if $col == $default_sum {
  42. // if last col, then no gap
  43. padding-right: 0;
  44. }@else{
  45. padding-right: $gap;
  46. }
  47. &:last-child{padding-right: 0;}
  48. // no offset with flex ??
  49. // margin-left: percentage(($col/$sum)*$offset);
  50. // col width
  51. flex-basis: percentage($col/$sum);
  52. }
  53. @for $c from 1 through $default_sum {
  54. .col-#{$c} {
  55. @include col($c);
  56. }
  57. // small
  58. .small-col-#{$c} {
  59. @media only screen and (max-width: $small-bp) {
  60. @include col($c);
  61. }
  62. }
  63. // medium
  64. .med-col-#{$c} {
  65. @media only screen and (min-width: $small-bp+1) and (max-width: $med-bp) {
  66. @include col($c);
  67. }
  68. }
  69. // large
  70. .large-col-#{$c} {
  71. @media only screen and (min-width: $med-bp+1) {
  72. @include col($c);
  73. }
  74. }
  75. }
  76. @for $c from 1 through $default_sum - 1 {
  77. @for $o from 1 through $default_sum - $c {
  78. .col-#{$c}-offset-#{$o} {
  79. @include col($c, $o);
  80. }
  81. }
  82. }
  83. // TODO: replace with align-self:flex-start or flex-end
  84. // .col.float-right{
  85. // float: right;
  86. // padding-right: 0;
  87. // padding-left: $default_gap;
  88. // }