_grid-flex.scss 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. %col-reset {
  18. box-sizing: border-box;
  19. }
  20. @mixin col($col, $offset: 0, $sum: $default_sum, $gap: $default_gap, $align: top) {
  21. @extend %col-reset;
  22. padding-left: $gap*$offset;
  23. @if $col == $default_sum {
  24. // if last col, then no gap
  25. padding-right: 0;
  26. }@else{
  27. padding-right: $gap;
  28. }
  29. &:last-child{padding-right: 0;}
  30. // no offset with flex ??
  31. // margin-left: percentage(($col/$sum)*$offset);
  32. // col width
  33. flex-basis: percentage($col/$sum);
  34. }
  35. @for $c from 1 through $default_sum {
  36. .col-#{$c} {
  37. @include col($c);
  38. }
  39. // small
  40. .small-col-#{$c} {
  41. @media only screen and (max-width: $small-bp) {
  42. @include col($c);
  43. }
  44. }
  45. // medium
  46. .med-col-#{$c} {
  47. @media only screen and (min-width: $small-bp+1) and (max-width: $med-bp) {
  48. @include col($c);
  49. }
  50. }
  51. // large
  52. .large-col-#{$c} {
  53. @media only screen and (min-width: $med-bp+1) {
  54. @include col($c);
  55. }
  56. }
  57. }
  58. @for $c from 1 through $default_sum - 1 {
  59. @for $o from 1 through $default_sum - $c {
  60. .col-#{$c}-offset-#{$o} {
  61. @include col($c, $o);
  62. }
  63. }
  64. }
  65. // TODO: replace with align-self:flex-start or flex-end
  66. // .col.float-right{
  67. // float: right;
  68. // padding-right: 0;
  69. // padding-left: $default_gap;
  70. // }