Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  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.  
  9. // Name of the next breakpoint, or null for the last breakpoint.
  10. //
  11. // >> breakpoint-next(sm)
  12. // md
  13. // >> breakpoint-next(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  14. // md
  15. // >> breakpoint-next(sm, @breakpoint-names: (xs sm md lg xl))
  16. // md
  17. .function-breakpoint-next(@name, @breakpoints: @grid-breakpoints, @breakpoint-names: map-keys(@breakpoints)) {
  18. @n: index(@breakpoint-names, @name);
  19. return: if(@n < length(@breakpoint-names), extract(@breakpoint-names, @n + 1), null);
  20. }
  21.  
  22. // Minimum breakpoint width. Null for the smallest (first) breakpoint.
  23. //
  24. // >> breakpoint-min(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  25. // 576px
  26. .function-breakpoint-min(@name, @breakpoints: @grid-breakpoints) {
  27. @min: map-get(@breakpoints, @name);
  28. return: if(@min != 0, @min, null);
  29. }
  30.  
  31. // Maximum breakpoint width. Null for the largest (last) breakpoint.
  32. // The maximum value is calculated as the minimum of the next one less 0.1.
  33. //
  34. // >> breakpoint-max(sm, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
  35. // 767px
  36. .function-breakpoint-max(@name, @breakpoints: @grid-breakpoints) {
  37. @next: breakpoint-next(@name, @breakpoints);
  38. return: if(@next, breakpoint-min(@next, @breakpoints) - 1px, null);
  39. }
  40.  
  41. // Returns a blank string if smallest breakpoint, otherwise returns the name with a dash infront.
  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.  
  52. // Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
  53. // Makes the @content apply to the given breakpoint and wider.
  54. .media-breakpoint-up(@name, @breakpoints: @grid-breakpoints) {
  55. @min: breakpoint-min(@name, @breakpoints);
  56. & when (@min) {
  57. @media (min-width: @min) {
  58. @content;
  59. }
  60. }
  61. & when not (@min) {
  62. @content;
  63. }
  64. }
  65.  
  66. // Media of at most the maximum breakpoint width. No query for the largest breakpoint.
  67. // Makes the @content apply to the given breakpoint and narrower.
  68. .media-breakpoint-down(@name, @breakpoints: @grid-breakpoints) {
  69. @max: breakpoint-max(@name, @breakpoints);
  70. & when (@max) {
  71. @media (max-width: @max) {
  72. @content;
  73. }
  74. }
  75. & when not (@max) {
  76. @content;
  77. }
  78. }
  79.  
  80. // Media that spans multiple breakpoint widths.
  81. // Makes the @content apply between the min and max breakpoints
  82. .media-breakpoint-between(@lower, @upper, @breakpoints: @grid-breakpoints) {
  83. @min: breakpoint-max(@lower, @breakpoints);
  84. @max: breakpoint-max(@upper, @breakpoints);
  85.  
  86. @media (min-width: @min) and (max-width: @max) {
  87. @content;
  88. }
  89. }
  90.  
  91. // Media between the breakpoint's minimum and maximum widths.
  92. // No minimum for the smallest breakpoint, and no maximum for the largest one.
  93. // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
  94. .media-breakpoint-only(@name, @breakpoints: @grid-breakpoints) {
  95. @min: breakpoint-min(@name, @breakpoints);
  96. @max: breakpoint-max(@name, @breakpoints);
  97.  
  98. & when (@min != null and @max != null) {
  99. @media (min-width: @min) and (max-width: @max) {
  100. @content;
  101. }
  102. }
  103. & when not (@min != null and @max != null) if @max == null {
  104. .media-breakpoint-up(@name)
  105. } @else if @min == null {
  106. .media-breakpoint-down(@name)
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement