blob: 26e6b11cc5ec4a0b9d965f07a28ee7b89a2118e9 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<p>Element queries vs Media Queries. Drag the slider to see the effect</p>
2
3<style>
4
5 .demo-grid {
6 margin-bottom: 16px;
7 }
8 .demo-grid .mdl-grid,
9 .demo-grid .mdlext-grid {
10 /*padding: 0;*/
11 }
12 .demo-grid .mdl-cell,
13 .demo-grid .mdlext-cell {
14 background: rgb(63,81,181);
15 text-align: center;
16 color: white;
17 padding: 10px;
18 border: 1px solid #aaaaaa;
19 }
20 .demo-grid .mdl-cell:nth-child(odd),
21 .demo-grid .mdlext-cell:nth-child(odd) {
22 background: rgb(33,150,243);
23 }
24 .demo-grid-c .mdl-cell,
25 .demo-grid-c .mdlext-cell {
26 background: rgb(255,213,79);
27 color: #000;
28 border: 0;
29 }
30 .demo-grid-c .mdl-cell:nth-child(odd),
31 .demo-grid-c .mdlext-cell:nth-child(odd) {
32 background: rgb(165,214,167);
33 color: #000;
34 }
35</style>
36
37
38<p id="grid-container-width" style="text-align: center;">
39 <strong>100</strong>%
40 <input class="mdl-slider mdl-js-slider" type="range" min="50" max="100" value="100" step="10" tabindex="0">
41</p>
42
43<div style="border: 1px solid #dddddd;">
44 <div id="grid-container" style="margin: 0 auto;">
45
46 <h5>mdlext-grid, using element queries</h5>
47 <div class="demo-grid">
48 <div class="mdlext-grid mdlext-grid--no-spacing">
49 <div class="mdlext-cell mdlext-cell--1-col">1</div>
50 <div class="mdlext-cell mdlext-cell--1-col">1</div>
51 <div class="mdlext-cell mdlext-cell--1-col">1</div>
52 <div class="mdlext-cell mdlext-cell--1-col">1</div>
53 <div class="mdlext-cell mdlext-cell--1-col">1</div>
54 <div class="mdlext-cell mdlext-cell--1-col">1</div>
55 <div class="mdlext-cell mdlext-cell--1-col">1</div>
56 <div class="mdlext-cell mdlext-cell--1-col">1</div>
57 <div class="mdlext-cell mdlext-cell--1-col">1</div>
58 <div class="mdlext-cell mdlext-cell--1-col">1</div>
59 <div class="mdlext-cell mdlext-cell--1-col">1</div>
60 <div class="mdlext-cell mdlext-cell--1-col">1</div>
61 </div>
62 </div>
63
64 <div class="demo-grid demo-grid-c">
65 <div class="mdlext-grid mdlext-grid--no-spacing">
66 <div class="mdlext-cell mdlext-cell--4-col mdlext-cell--2-col-tablet mdlext-cell--1-col-phone">4 (2 tablet, 1 phone)</div>
67 <div class="mdlext-cell mdlext-cell--6-col mdlext-cell--4-col-tablet mdlext-cell--3-col-phone">6 (4 tablet, 3 phone)</div>
68 <div class="mdlext-cell mdlext-cell--2-col mdlext-cell--2-col-tablet mdlext-cell--hide-phone">2 (2 tablet, hide phone)</div>
69 </div>
70 </div>
71
72
73 <h5>mdl-grid, using media queries</h5>
74 <div class="demo-grid">
75 <div class="mdl-grid mdl-grid--no-spacing">
76 <div class="mdl-cell mdl-cell--1-col">1</div>
77 <div class="mdl-cell mdl-cell--1-col">1</div>
78 <div class="mdl-cell mdl-cell--1-col">1</div>
79 <div class="mdl-cell mdl-cell--1-col">1</div>
80 <div class="mdl-cell mdl-cell--1-col">1</div>
81 <div class="mdl-cell mdl-cell--1-col">1</div>
82 <div class="mdl-cell mdl-cell--1-col">1</div>
83 <div class="mdl-cell mdl-cell--1-col">1</div>
84 <div class="mdl-cell mdl-cell--1-col">1</div>
85 <div class="mdl-cell mdl-cell--1-col">1</div>
86 <div class="mdl-cell mdl-cell--1-col">1</div>
87 <div class="mdl-cell mdl-cell--1-col">1</div>
88 </div>
89 </div>
90
91 <div class="demo-grid demo-grid-c">
92 <div class="mdl-grid mdl-grid--no-spacing">
93 <div class="mdl-cell mdl-cell--4-col mdl-cell--2-col-tablet mdl-cell--1-col-phone">4 (2 tablet, 1 phone)</div>
94 <div class="mdl-cell mdl-cell--6-col mdl-cell--4-col-tablet mdl-cell--3-col-phone">6 (4 tablet, 3 phone)</div>
95 <div class="mdl-cell mdl-cell--2-col mdl-cell--2-col-tablet mdl-cell--hide-phone">2 (2 tablet, hide phone)</div>
96 </div>
97 </div>
98 </div>
99</div>
100
101<script>
102 'use strict';
103 window.addEventListener('load', function() {
104 (function() {
105 'use strict';
106 var widthLabel = document.querySelector('#grid-container-width strong');
107 var slider = document.querySelector('#grid-container-width input');
108
109 slider.addEventListener('input', function(e) {
110 setWidth(this.value);
111 }.bind(slider));
112
113 function setWidth(value) {
114 widthLabel.innerText = value;
115 document.querySelector('#grid-container').style.width = value + '%';
116 eqjs.refreshNodes();
117 eqjs.query(undefined, true);
118 }
119 }());
120 });
121</script>