Skip to content

Commit 27a0198

Browse files
committed
Demo: add 3 breakpoint grid
1 parent d95a255 commit 27a0198

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

css_grid/base.css

+40-9
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,8 @@ a:active {
180180
.container-h {
181181
/* breakpoint */
182182
--w: 400px;
183-
/* num of columns when over breakpoint */
184-
--n: 5;
185-
/* num of columns when under breakpoint */
186-
--m: 1;
183+
--n: 5; /* num of columns when over breakpoint */
184+
--m: 1; /* num of columns when under breakpoint */
187185

188186
display: grid;
189187
grid-template-columns: repeat(
@@ -196,19 +194,17 @@ a:active {
196194
),
197195
1fr
198196
)
199-
);
197+
);
200198
gap: 5px;
201199
}
202200

203201
.container-i {
204202
/* first breakpoint */
205203
--w1: 800px;
206-
/* number of columns when over first breakpoint */
207-
--n: 5;
204+
--n: 5; /* number of columns when over first breakpoint */
208205
/* second breakpoint */
209206
--w2: 400px;
210-
/* number of columns when over second breakpoint */
211-
--m: 2;
207+
--m: 2; /* number of columns when over second breakpoint */
212208
/* cols will be 100% when under second breakpoint */
213209

214210
display: grid;
@@ -230,6 +226,41 @@ a:active {
230226
gap: 5px;
231227
}
232228

229+
.container-j {
230+
/* first breakpoint */
231+
--w1: 800px; /* number of columns when over first breakpoint */
232+
--n: 5;
233+
/* second breakpoint */
234+
--w2: 600px; /* number of columns when over second breakpoint */
235+
--m: 3;
236+
/* third breakpoint*/
237+
--w3: 400px;
238+
--p: 2; /* number of columns when over third breakpoint */
239+
/* cols will be 100% when under third breakpoint */
240+
241+
display: grid;
242+
grid-template-columns: repeat(
243+
auto-fill,
244+
minmax(
245+
clamp(
246+
clamp(
247+
clamp(
248+
100%/ (var(--n) + 1) + 0.1%,
249+
(var(--w1) - 100vw) * 1000,
250+
100%/ (var(--m) + 1) + 0.1%
251+
),
252+
(var(--w2) - 100vw) * 1000,
253+
100%/ (var(--p) + 1) + 0.1%
254+
),
255+
(var(--w3) - 100vw) * 1000,
256+
100%
257+
),
258+
1fr
259+
)
260+
);
261+
gap: 5px;
262+
}
263+
233264
/* COMPONENTS ------------------------------------------------------------- */
234265

235266
/* COSMETIC --------------------------------------------------------------- */

css_grid/index.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ <h1> Named areas.</h1>
145145
<li>y</li>
146146
<li>z</li>
147147
</ul>
148-
148+
149149
<div class="container-g base">
150150
<div class="basic-box">A</div>
151151
<div class="basic-box">A</div>
@@ -176,6 +176,16 @@ <h1> Named areas.</h1>
176176
<div class="basic-box">A</div>
177177
</div>
178178

179+
<div class="container-j base">
180+
<div class="basic-box">A</div>
181+
<div class="basic-box">A</div>
182+
<div class="basic-box">A</div>
183+
<div class="basic-box">A</div>
184+
<div class="basic-box">A</div>
185+
<div class="basic-box">A</div>
186+
<div class="basic-box">A</div>
187+
</div>
188+
179189
<p> See <a href="https://css-tricks.com/responsive-layouts-fewer-media-queries/" target="_blank" rel="noopener noreferrer">Responsive Layouts, Fewer Media Queries</a>
180190

181191

0 commit comments

Comments
 (0)