No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_breakpoints.scss 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Breakpoint viewport sizes and media queries.
  2. //
  3. // Breakpoints are defined as a map of (name: minimum width), order from small to large:
  4. //
  5. // (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px)
  6. //
  7. // The map defined in the `$grid-breakpoints` global variable is used as the `$breakpoints` argument by default.
  8. // Name of the next breakpoint, or null for the last breakpoint.
  9. //
  10. // >> breakpoint-next(sm)
  11. // md
  12. // >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  13. // md
  14. // >> breakpoint-next(sm, $breakpoint-names: (xs sm md lg xl))
  15. // md
  16. @function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) {
  17. $n: index($breakpoint-names, $name);
  18. @return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null);
  19. }
  20. // Minimum breakpoint width. Null for the smallest (first) breakpoint.
  21. //
  22. // >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  23. // 576px
  24. @function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
  25. $min: map-get($breakpoints, $name);
  26. @return if($min != 0, $min, null);
  27. }
  28. // Maximum breakpoint width. Null for the largest (last) breakpoint.
  29. // The maximum value is calculated as the minimum of the next one less 0.02px
  30. // to work around the limitations of `min-` and `max-` prefixes and viewports with fractional widths.
  31. // See https://www.w3.org/TR/mediaqueries-4/#mq-min-max
  32. // Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari.
  33. // See https://bugs.webkit.org/show_bug.cgi?id=178261
  34. //
  35. // >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  36. // 767.98px
  37. @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
  38. $next: breakpoint-next($name, $breakpoints);
  39. @return if($next, breakpoint-min($next, $breakpoints) - .02px, null);
  40. }
  41. // Returns a blank string if smallest breakpoint, otherwise returns the name with a dash in front.
  42. // Useful for making responsive utilities.
  43. //
  44. // >> breakpoint-infix(xs, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  45. // "" (Returns a blank string)
  46. // >> breakpoint-infix(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  47. // "-sm"
  48. @function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
  49. @return if(breakpoint-min($name, $breakpoints) == null, "", "-#{$name}");
  50. }
  51. // Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
  52. // Makes the @content apply to the given breakpoint and wider.
  53. @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
  54. $min: breakpoint-min($name, $breakpoints);
  55. @if $min {
  56. @media (min-width: $min) {
  57. @content;
  58. }
  59. } @else {
  60. @content;
  61. }
  62. }
  63. // Media of at most the maximum breakpoint width. No query for the largest breakpoint.
  64. // Makes the @content apply to the given breakpoint and narrower.
  65. @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
  66. $max: breakpoint-max($name, $breakpoints);
  67. @if $max {
  68. @media (max-width: $max) {
  69. @content;
  70. }
  71. } @else {
  72. @content;
  73. }
  74. }
  75. // Media that spans multiple breakpoint widths.
  76. // Makes the @content apply between the min and max breakpoints
  77. @mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) {
  78. $min: breakpoint-min($lower, $breakpoints);
  79. $max: breakpoint-max($upper, $breakpoints);
  80. @if $min != null and $max != null {
  81. @media (min-width: $min) and (max-width: $max) {
  82. @content;
  83. }
  84. } @else if $max == null {
  85. @include media-breakpoint-up($lower, $breakpoints) {
  86. @content;
  87. }
  88. } @else if $min == null {
  89. @include media-breakpoint-down($upper, $breakpoints) {
  90. @content;
  91. }
  92. }
  93. }
  94. // Media between the breakpoint's minimum and maximum widths.
  95. // No minimum for the smallest breakpoint, and no maximum for the largest one.
  96. // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
  97. @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
  98. $min: breakpoint-min($name, $breakpoints);
  99. $max: breakpoint-max($name, $breakpoints);
  100. @if $min != null and $max != null {
  101. @media (min-width: $min) and (max-width: $max) {
  102. @content;
  103. }
  104. } @else if $max == null {
  105. @include media-breakpoint-up($name, $breakpoints) {
  106. @content;
  107. }
  108. } @else if $min == null {
  109. @include media-breakpoint-down($name, $breakpoints) {
  110. @content;
  111. }
  112. }
  113. }