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.
 
 
 
 
 

87 lines
2.9 KiB

  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: 544px, md: 768px)
  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: 544px, md: 768px))
  13. // md
  14. // >> breakpoint-next(sm, $breakpoint-names: (xs sm md))
  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: 544px, md: 768px))
  23. // 544px
  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.1.
  30. //
  31. // >> breakpoint-max(sm, (xs: 0, sm: 544px, md: 768px))
  32. // 767px
  33. @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
  34. $next: breakpoint-next($name, $breakpoints);
  35. @return if($next, breakpoint-min($next, $breakpoints) - 1px, null);
  36. }
  37. // Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
  38. // Makes the @content apply to the given breakpoint and wider.
  39. @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
  40. $min: breakpoint-min($name, $breakpoints);
  41. @if $min {
  42. @media (min-width: $min) {
  43. @content;
  44. }
  45. } @else {
  46. @content;
  47. }
  48. }
  49. // Media of at most the maximum breakpoint width. No query for the largest breakpoint.
  50. // Makes the @content apply to the given breakpoint and narrower.
  51. @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
  52. $max: breakpoint-max($name, $breakpoints);
  53. @if $max {
  54. @media (max-width: $max) {
  55. @content;
  56. }
  57. } @else {
  58. @content;
  59. }
  60. }
  61. // Media between the breakpoint's minimum and maximum widths.
  62. // No minimum for the smallest breakpoint, and no maximum for the largest one.
  63. // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
  64. @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
  65. @include media-breakpoint-up($name, $breakpoints) {
  66. @include media-breakpoint-down($name, $breakpoints) {
  67. @content;
  68. }
  69. }
  70. }
  71. // Media that spans multiple breakpoint widths.
  72. // Makes the @content apply between the min and max breakpoints
  73. @mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) {
  74. @include media-breakpoint-up($lower, $breakpoints) {
  75. @include media-breakpoint-down($upper, $breakpoints) {
  76. @content;
  77. }
  78. }
  79. }