_responsive.less 3.21 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
// /**
//  * Copyright © Magento, Inc. All rights reserved.
//  * See COPYING.txt for license details.
//  */

//  # Responsive
//  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.
//
//  To see the media queries work resize window to understand which breakpoint is applied.
//  ```
//  <div class="example-responsive-block">
//      are applied.
//  </div>
//  ```

.example-responsive-block {
    padding: 10px;
}

.media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__m) {
    .example-responsive-block {
        background: #ffc;
    }
    .example-responsive-block:before {
        content: 'Mobile styles ';
        font-weight: bold;
    }
}

.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
    .example-responsive-block {
        background: #ccf;
    }
    .example-responsive-block:before {
        content: 'Desktop styles ';
        font-weight: bold;
    }
}

//  # Responsive mixins usage
//
//  For grouping style rules in certain media queries .media-width() mixin used.
//  ```css
// .media-width(<@extremum>, <@break>);
//  ```
//  <nobr><code>@extremum: max|min</code></nobr> - sets whether to use **min-width** or **max-width** in media query condition<br />
//  <nobr><code>@break: value</code></nobr> - sets the value of breakpoint to compare with in media query condition.<br />
//  For example
//  ```css
//  .media-width(@extremum, @break) when (@extremum = 'max') and (@break = @screen__s) {
//      your styles
//  }
//  ```
//  It will be complied to
//  ```css
//  @media only screen and (max-width: 640px) {
//      your styles
//  }
//  ```
//  &nbsp;
//
//  # Media query style groups separation variables
//
//  <code>@media-common: true|false</code> - sets whether to output common styles.
//  For common styles every time you want to add some styles you should use
//  ```css
//  & when (@media-common = true) {
//      your styles
//  }
//  ```
//
//  <code>@media-target: all|desktop|mobile</code> - Sets target device for styles output
//  ```css
//  & when (@media-target = 'mobile'),
//  (@media-target = 'all') {
//     @media only screen and (max-width: (@screen__xs - 1)) {
//         .media-width('max', @screen__xs);
//     }
// }
//  ```
//
//  ## Gathering
//
//  Everything that you include in collector mixins above will go in place where they declarated.
//  As example all
//  ```css
//  .media-width(@extremum, @break) {
//      your code
//  }
//  ```
//  Will go to
//  ```css
//  .media-width(@extremum, @break));
//  ```
//  By default you can find it <code>_responsive.less</code> file in li
//  &nbsp;
//
//  # Responsive breakpoints
//  In Magento UI library there are predefined variables for breakpoints.
//  ```css
//  @screen__xxs: 320px;
//  @screen__xs: 480px;
//  @screen__s: 640px;
//  @screen__m: 768px;
//  @screen__l: 1024px;
//  @screen__xl: 1440px;
//  ```
//  &nbsp;