_utilities.widths.scss 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* ==========================================================================
  2. #WIDTHS
  3. ========================================================================== */
  4. /**
  5. * inuitcss generates a series of utility classes that give a fluid width to
  6. * whichever element they’re applied, e.g.:
  7. *
  8. * <img src="" alt="" class="u-1/2" />
  9. *
  10. * These classes are most commonly used in conjunction with our layout system,
  11. * e.g.:
  12. *
  13. * <div class="o-layout__item u-1/2">
  14. *
  15. * By default, inuitcss will also generate responsive variants of each of these
  16. * classes by using your Sass MQ configuration, e.g.:
  17. *
  18. * <div class="o-layout__item u-1/1 u-1/2@tablet u-1/3@desktop">
  19. *
  20. * Optionally, inuitcss can generate offset classes which can push and pull
  21. * elements left and right by a specified amount, e.g.:
  22. *
  23. * <div class="o-layout__item u-2/3 u-pull-1/3">
  24. *
  25. * This is useful for making very granular changes to the rendered order of
  26. * items in a layout.
  27. *
  28. * N.B. This option is turned off by default.
  29. */
  30. // Which fractions would you like in your grid system(s)? By default, inuitcss
  31. // provides you fractions of one whole, halves, thirds, quarters and fifths,
  32. // e.g.:
  33. //
  34. // .u-1/2
  35. // .u-2/5
  36. // .u-3/4
  37. // .u-2/3
  38. $inuit-fractions: 1 2 3 4 5 !default;
  39. // Optionally, inuitcss can generate classes to offset items by a certain width.
  40. // Would you like to generate these types of class as well? E.g.:
  41. //
  42. // .u-push-1/3
  43. // .u-pull-2/4
  44. // .u-pull-1/5
  45. // .u-push-2/3
  46. $inuit-offsets: false !default;
  47. // By default, inuitcss uses fractions-like classes like `<div class="u-1/4">`.
  48. // You can change the `/` to whatever you fancy with this variable.
  49. $inuit-widths-delimiter: \/ !default;
  50. // When using Sass-MQ, this defines the separator for the breakpoints suffix
  51. // in the class name. By default, we are generating the responsive suffixes
  52. // for the classes with a `@` symbol so you get classes like:
  53. // <div class="u-3/12@mobile">
  54. $inuit-widths-breakpoint-separator: \@ !default;
  55. // A mixin to spit out our width classes. Pass in the columns we want the widths
  56. // to have, and an optional suffix for responsive widths. E.g. to create thirds
  57. // and quarters for a small breakpoint:
  58. //
  59. // @include widths(3 4, -sm);
  60. @mixin inuit-widths($columns, $breakpoint: null) {
  61. // Loop through the number of columns for each denominator of our fractions.
  62. @each $denominator in $columns {
  63. // Begin creating a numerator for our fraction up until we hit the
  64. // denominator.
  65. @for $numerator from 1 through $denominator {
  66. // Build a class in the format `.u-3/4[@<breakpoint>]`.
  67. .u-#{$numerator}#{$inuit-widths-delimiter}#{$denominator}#{$breakpoint} {
  68. width: ($numerator / $denominator) * 100% !important;
  69. }
  70. @if ($inuit-offsets == true) {
  71. /**
  72. * 1. Reset any leftover or conflicting `left`/`right` values.
  73. */
  74. // Build a class in the format `.u-push-1/2[@<breakpoint>]`.
  75. .u-push-#{$numerator}#{$inuit-widths-delimiter}#{$denominator}#{$breakpoint} {
  76. position: relative !important;
  77. right: auto !important; /* [1] */
  78. left: ($numerator / $denominator) * 100% !important;
  79. }
  80. // Build a class in the format `.u-pull-5/6[@<breakpoint>]`.
  81. .u-pull-#{$numerator}#{$inuit-widths-delimiter}#{$denominator}#{$breakpoint} {
  82. position: relative !important;
  83. right: ($numerator / $denominator) * 100% !important;
  84. left: auto !important; /* [1] */
  85. }
  86. }
  87. }
  88. }
  89. @if ($inuit-offsets == true and $breakpoint != null) {
  90. // Create auto push and pull classes.
  91. .u-push-none#{$breakpoint} {
  92. left: auto !important;
  93. }
  94. .u-pull-none#{$breakpoint} {
  95. right: auto !important;
  96. }
  97. }
  98. }
  99. /**
  100. * A series of width helper classes that you can use to size things like grid
  101. * systems. Classes take a fraction-like format (e.g. `.u-2/3`). Use these in
  102. * your markup:
  103. *
  104. * <div class="u-7/12">
  105. *
  106. * The following will generate widths helper classes based on the fractions
  107. * defined in the `$inuit-fractions` list.
  108. */
  109. @include inuit-widths($inuit-fractions);
  110. /**
  111. * If we’re using Sass-MQ, automatically generate grid system(s) for each of our
  112. * defined breakpoints, and give them a Responsive Suffix, e.g.:
  113. *
  114. * <div class="u-3/12@mobile">
  115. */
  116. @if (variable-exists(mq-breakpoints)) {
  117. @each $inuit-bp-name, $inuit-bp-value in $mq-breakpoints {
  118. @include mq($from: $inuit-bp-name) {
  119. @include inuit-widths($inuit-fractions, #{$inuit-widths-breakpoint-separator}#{$inuit-bp-name});
  120. }
  121. }
  122. }