_grid-framework.scss 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. //daihong AT 20160426
  18. }
  19. }
  20. // [converter] This is defined recursively in LESS, but Sass supports real loops
  21. @mixin float-grid-columns($class, $i: 1, $list: ".col-#{$class}-#{$i}") {
  22. @for $i from (1 + 1) through $grid-columns {
  23. $list: "#{$list}, .col-#{$class}-#{$i}";
  24. }
  25. #{$list} {
  26. float: left;
  27. }
  28. }
  29. @mixin calc-grid-column($index, $class, $type) {
  30. @if ($type == width) and ($index > 0) {
  31. .col-#{$class}-#{$index} {
  32. width: percentage(($index / $grid-columns));
  33. }
  34. }
  35. @if ($type == push) and ($index > 0) {
  36. .col-#{$class}-push-#{$index} {
  37. left: percentage(($index / $grid-columns));
  38. }
  39. }
  40. @if ($type == push) and ($index == 0) {
  41. .col-#{$class}-push-0 {
  42. left: auto;
  43. }
  44. }
  45. @if ($type == pull) and ($index > 0) {
  46. .col-#{$class}-pull-#{$index} {
  47. right: percentage(($index / $grid-columns));
  48. }
  49. }
  50. @if ($type == pull) and ($index == 0) {
  51. .col-#{$class}-pull-0 {
  52. right: auto;
  53. }
  54. }
  55. @if ($type == offset) {
  56. .col-#{$class}-offset-#{$index} {
  57. margin-left: percentage(($index / $grid-columns));
  58. }
  59. }
  60. }
  61. // [converter] This is defined recursively in LESS, but Sass supports real loops
  62. @mixin loop-grid-columns($columns, $class, $type) {
  63. @for $i from 0 through $columns {
  64. @include calc-grid-column($i, $class, $type);
  65. }
  66. }
  67. // Create grid for specific class
  68. @mixin make-grid($class) {
  69. @include float-grid-columns($class);
  70. @include loop-grid-columns($grid-columns, $class, width);
  71. @include loop-grid-columns($grid-columns, $class, pull);
  72. @include loop-grid-columns($grid-columns, $class, push);
  73. @include loop-grid-columns($grid-columns, $class, offset);
  74. }