_grid.scss 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // http://www.thesassway.com/intermediate/simple-grid-mixins
  2. $default_gap: 1em;
  3. $default_sum: 12;
  4. $small-bp:768px;
  5. $med-bp:1080px;
  6. // $large-bp:1900px;
  7. @mixin row() {
  8. // font-size: 0;
  9. // white-space: nowrap;
  10. position: relative;
  11. >*{
  12. font-size: 16px;
  13. }
  14. }
  15. %col-reset {
  16. width: 100%;
  17. // display: inline-block;
  18. // white-space:normal;
  19. // font-size: 16px;
  20. float:left;
  21. box-sizing: border-box;
  22. }
  23. @mixin col($col, $offset: 0, $sum: $default_sum, $gap: $default_gap, $align: top) {
  24. @extend %col-reset;
  25. padding-left: $gap*$offset;
  26. @if $col == $default_sum {
  27. padding-right: 0;
  28. }@else{
  29. padding-right: $gap;
  30. }
  31. &:last-child{padding-right: 0;}
  32. margin-left: percentage(($col/$sum)*$offset);
  33. // @media only screen and (min-width: 768px) {
  34. width: percentage($col/$sum);
  35. // vertical-align: $align;
  36. // }
  37. }
  38. .row{
  39. @include row;
  40. // html:not(.js) &{
  41. // overflow-y: auto;
  42. // }
  43. }
  44. @for $c from 1 through $default_sum {
  45. .col-#{$c} {
  46. @include col($c);
  47. }
  48. // small
  49. .small-col-#{$c} {
  50. @media only screen and (max-width: $small-bp) {
  51. @include col($c);
  52. }
  53. }
  54. // medium
  55. .med-col-#{$c} {
  56. @media only screen and (min-width: $small-bp+1) and (max-width: $med-bp) {
  57. @include col($c);
  58. }
  59. }
  60. // large
  61. .large-col-#{$c} {
  62. @media only screen and (min-width: $med-bp+1) {
  63. @include col($c);
  64. }
  65. }
  66. }
  67. @for $c from 1 through $default_sum - 1 {
  68. @for $o from 1 through $default_sum - $c {
  69. .col-#{$c}-offset-#{$o} {
  70. @include col($c, $o);
  71. }
  72. }
  73. }
  74. .col.float-right{
  75. float: right;
  76. padding-right: 0;
  77. padding-left: $default_gap;
  78. }