_responsive.less 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // /**
  2. // * Copyright © Magento, Inc. All rights reserved.
  3. // * See COPYING.txt for license details.
  4. // */
  5. // # Responsive
  6. // Magento UI library provides a strong approach for working with media queries. It`s based on recursive call of <nobr><code>.media-width()</code></nobr> mixin defined anywhere in project but invoked in one place in <nobr><code>lib/web/css/source/lib/_responsive.less</code></nobr>. That's why in the resulting <code>styles.css</code> we have every media query only once with all the rules there, not a multiple calls for the same query.
  7. //
  8. // To see the media queries work resize window to understand which breakpoint is applied.
  9. // ```
  10. // <div class="example-responsive-block">
  11. // are applied.
  12. // </div>
  13. // ```
  14. .example-responsive-block {
  15. padding: 10px;
  16. }
  17. .media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
  18. .example-responsive-block {
  19. background: #ffc;
  20. }
  21. .example-responsive-block:before {
  22. content: 'Mobile styles ';
  23. font-weight: bold;
  24. }
  25. }
  26. .media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
  27. .example-responsive-block {
  28. background: #ccf;
  29. }
  30. .example-responsive-block:before {
  31. content: 'Desktop styles ';
  32. font-weight: bold;
  33. }
  34. }
  35. // # Responsive mixins usage
  36. //
  37. // For grouping style rules in certain media queries .media-width() mixin used.
  38. // ```css
  39. // .media-width(<@extremum>, <@break>);
  40. // ```
  41. // <nobr><code>@extremum: max|min</code></nobr> - sets whether to use **min-width** or **max-width** in media query condition<br />
  42. // <nobr><code>@break: value</code></nobr> - sets the value of breakpoint to compare with in media query condition.<br />
  43. // For example
  44. // ```css
  45. // .media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__s) {
  46. // your styles
  47. // }
  48. // ```
  49. // It will be complied to
  50. // ```css
  51. // @media only screen and (max-width: 640px) {
  52. // your styles
  53. // }
  54. // ```
  55. // &nbsp;
  56. //
  57. // # Media query style groups separation variables
  58. //
  59. // <code>@media-common: true|false</code> - sets whether to output common styles.
  60. // For common styles every time you want to add some styles you should use
  61. // ```css
  62. // & when (@media-common = true) {
  63. // your styles
  64. // }
  65. // ```
  66. //
  67. // <code>@media-target: all|desktop|mobile</code> - Sets target device for styles output
  68. // ```css
  69. // & when (@media-target = 'mobile'),
  70. // (@media-target = 'all') {
  71. // @media only screen and (max-width: (@screen__xs - 1)) {
  72. // .media-width('max', @screen__xs);
  73. // }
  74. // }
  75. // ```
  76. //
  77. // ## Gathering
  78. //
  79. // Everything that you include in collector mixins above will go in place where they declarated.
  80. // As example all
  81. // ```css
  82. // .media-width(@extremum, @break) {
  83. // your code
  84. // }
  85. // ```
  86. // Will go to
  87. // ```css
  88. // .media-width(@extremum, @break));
  89. // ```
  90. // By default you can find it <code>_responsive.less</code> file in li
  91. // &nbsp;
  92. //
  93. // # Responsive breakpoints
  94. // In Magento UI library there are predefined variables for breakpoints.
  95. // ```css
  96. // @screen__xxs: 320px;
  97. // @screen__xs: 480px;
  98. // @screen__s: 640px;
  99. // @screen__m: 768px;
  100. // @screen__l: 1024px;
  101. // @screen__xl: 1440px;
  102. // ```
  103. // &nbsp;