_grid-framework.scss 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Framework grid generation
  2. //
  3. // Used only by Bootstrap to generate the correct number of grid classes given
  4. // any value of `$grid-columns`.
  5. // [converter] This is defined recursively in LESS, but Sass supports real loops
  6. @mixin make-grid-columns($i: 1, $list: ".col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}") {
  7. @for $i from (1 + 1) through $grid-columns {
  8. $list: "#{$list}, .col-xs-#{$i}, .col-sm-#{$i}, .col-md-#{$i}, .col-lg-#{$i}";
  9. }
  10. #{$list} {
  11. position: relative;
  12. // Prevent columns from collapsing when empty
  13. min-height: 1px;
  14. // Inner gutter via padding
  15. padding-left: ceil(($grid-gutter-width / 2));
  16. padding-right: floor(($grid-gutter-width / 2));
  17. }
  18. }
  19. // [converter] This is defined recursively in LESS, but Sass supports real loops
  20. @mixin float-grid-columns($class, $i: 1, $list: ".col-#{$class}-#{$i}") {
  21. @for $i from (1 + 1) through $grid-columns {
  22. $list: "#{$list}, .col-#{$class}-#{$i}";
  23. }
  24. #{$list} {
  25. float: left;
  26. }
  27. }
  28. @mixin calc-grid-column($index, $class, $type) {
  29. @if ($type == width) and ($index > 0) {
  30. .col-#{$class}-#{$index} {
  31. width: percentage(($index / $grid-columns));
  32. }
  33. }
  34. @if ($type == push) and ($index > 0) {
  35. .col-#{$class}-push-#{$index} {
  36. left: percentage(($index / $grid-columns));
  37. }
  38. }
  39. @if ($type == push) and ($index == 0) {
  40. .col-#{$class}-push-0 {
  41. left: auto;
  42. }
  43. }
  44. @if ($type == pull) and ($index > 0) {
  45. .col-#{$class}-pull-#{$index} {
  46. right: percentage(($index / $grid-columns));
  47. }
  48. }
  49. @if ($type == pull) and ($index == 0) {
  50. .col-#{$class}-pull-0 {
  51. right: auto;
  52. }
  53. }
  54. @if ($type == offset) {
  55. .col-#{$class}-offset-#{$index} {
  56. margin-left: percentage(($index / $grid-columns));
  57. }
  58. }
  59. }
  60. // [converter] This is defined recursively in LESS, but Sass supports real loops
  61. @mixin loop-grid-columns($columns, $class, $type) {
  62. @for $i from 0 through $columns {
  63. @include calc-grid-column($i, $class, $type);
  64. }
  65. }
  66. // Create grid for specific class
  67. @mixin make-grid($class) {
  68. @include float-grid-columns($class);
  69. @include loop-grid-columns($grid-columns, $class, width);
  70. @include loop-grid-columns($grid-columns, $class, pull);
  71. @include loop-grid-columns($grid-columns, $class, push);
  72. @include loop-grid-columns($grid-columns, $class, offset);
  73. }