|
2 | 2 | layout: default
|
3 | 3 | group: fedg
|
4 | 4 | subgroup: E_rwd
|
5 |
| -title: CSS in a responsive design |
6 |
| -menu_title: CSS in a responsive design |
7 |
| -menu_order: 3 |
| 5 | +title: CSS in responsive design |
| 6 | +menu_title: CSS in responsive design |
| 7 | +menu_order: 2 |
8 | 8 | github_link: frontend-dev-guide/responsive-web-design/rwd_css.md
|
9 | 9 | ---
|
10 | 10 |
|
11 |
| -<h2 id="fedg_rwd_css_break">Breakpoints</h2> |
| 11 | +<h2>Overview</h2> |
12 | 12 |
|
13 |
| -Responsive design uses <a href="http://www.w3.org/TR/css3-mediaqueries/" target="_blank">CSS3 media queries</a> (an extension of the `@media` rule) to adapt the layout to the viewport. |
| 13 | +Stylesheets are the main tool in responsive web design (RWD) implementation. This topic describes the mechanisms and approaches to building RWD used in the default Magento themes. To re-use them in your custom theme, make your theme <a href="{{site.gdeurl}}frontend-dev-guide/themes/theme-inherit.html" target="_blank">inherit</a> from the main default Blank theme. |
14 | 14 |
|
15 |
| -Breakpoints are used in the CSS code to set up a viewport at which the design switches from the mobile to the desktop version. |
| 15 | +<h2 id="lib_rwd">Media queries in Magento default themes</h2> |
16 | 16 |
|
17 |
| -The Blank theme implements three breakpoints: |
| 17 | +The Blank and Luma theme styles are based on the <a href="{{site.gdeurl}}/css-topics/theme-ui-lib.html" target="_blank">Magento UI library</a>. The library uses <a href="http://en.wikipedia.org/wiki/Media_queries" target="_blank">CSS3 media queries</a>, an extension of the <code>@media</code> rule, to adapt the layout to the screen width. |
18 | 18 |
|
19 |
| -* The main one at 768px |
| 19 | +According to the approach implemented in the library, the <code>.media-width()</code> mixin can be used in any <code>.less</code> file in your theme, as many times as you need, but it is invoked only once, in <code>lib/web/css/source/lib/_responsive.less</code>. The resulting <code>styles.css</code> has only one call of each media query with all the rules there, instead of multiple calls for the same query. |
20 | 20 |
|
21 |
| - This breakpoints switches between mobile and desktop views. |
22 | 21 |
|
23 |
| -* 600px and 800px |
| 22 | +You can find more information about the Magento UI library responsive mixin usage in <code><your_Magento_instance>/pub/static/frontend/Magento/blank/en_US/css/docs/responsive.html</code> (view in a browser). |
24 | 23 |
|
25 |
| - These breakpoints affect how your catalog displays. |
| 24 | +<h2 id="fedg_rwd_css_break">Breakpoints</h2> |
26 | 25 |
|
27 |
| -CSS snippet: |
| 26 | +Breakpoints are used in the CSS code to set up the screen width at which the design switches from the mobile to the desktop version. |
28 | 27 |
|
29 |
| -<script src="https://gist.github.com/xcomSteveJohnson/be946288f49b228e04df.js"></script> |
| 28 | +The Blank theme implements the following <a href="{{site.gdeurl}}frontend-dev-guide/responsive-web-design/rwd_overview.html#fedg_rwd_terms" target="_blank">breakpoints</a>: |
| 29 | +<ul> |
| 30 | + <li>320px</li> |
| 31 | + <li>480px</li> |
| 32 | + <li>640px</li> |
| 33 | + <li>768px (in the Blank and Luma themes, this breakpoint switches between mobile and desktop views)</li> <li>1024px</li> |
| 34 | + <li>1440px</li> |
| 35 | +</ul> |
30 | 36 |
|
31 |
| -<h2 id="fedg_rwd_ex">Blank theme CSS examples</h2> |
32 | 37 |
|
33 |
| -To change the position of elements depending on the screen width, you must redefine which styles control their behavior. The following example compares a two-column display for mobile and desktop viewports. |
| 38 | +<h2>Mobile first</h2> |
34 | 39 |
|
35 |
| -Mobile version: The following figure shows the main and sidebar columns defined one after the other. |
| 40 | +In the Blank and Luma themes, the mobile first approach is used. It means that the styles for mobile devices (screen width less than 768px) are extended by the styles for the higher breakpoints. As the result, the extra styles are never loaded when a store is viewed on a mobile device. |
36 | 41 |
|
37 |
| - |
38 | 42 |
|
39 |
| -Desktop version: After the breakpoint of 768px is reached, the page uses CSS provided in the `@media` query to display the same columns side by side. |
| 43 | +In the Blank theme, the mobile and desktop styles are defined in separate files: |
40 | 44 |
|
41 |
| -CSS snippet: |
| 45 | +<ul> |
| 46 | +<li><a href="{{site.mage2000url}}app/design/frontend/Magento/blank/web/css/styles-l.less">styles-l.less</a> is used to generate desktop-specific styles (768px and higher).</li> |
| 47 | +<li><a href="{{site.mage2000url}}app/design/frontend/Magento/blank/web/css/styles-m.less">styles-m.less</a> is used to generate basic and mobile-specific styles.</li> |
| 48 | +</ul> |
42 | 49 |
|
43 |
| -<script src="https://gist.github.com/xcomSteveJohnson/787060623b87ef506bc0.js"></script> |
44 | 50 |
|
45 |
| -How it displays in a desktop browser: |
46 | 51 |
|
47 |
| - |
48 | 52 |
|
49 |
| -#### Related topics: |
| 53 | +<h2>Related topics</h2> |
50 | 54 |
|
51 | 55 | * <a href="{{ site.gdeurl }}frontend-dev-guide/themes/theme-create.html">Create a theme</a>
|
52 |
| -* <a href="{{ site.gdeurl }}frontend-dev-guide/responsive-web-design/theme-best-practices.html">Theme design best practices</a> |
53 | 56 | * <a href="{{ site.gdeurl }}frontend-dev-guide/css-topics/theme-ui-lib.html">Magento UI library</a>
|
54 | 57 | * <a href="{{ site.gdeurl }}frontend-dev-guide/responsive-web-design/rwd_js.html">JavaScript in a responsive design</a>
|
55 | 58 |
|
|
0 commit comments