-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
492 lines (427 loc) · 18.9 KB
/
index.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Flexbox Playground - Interactive CSS Flexbox Learning Tool</title>
<!-- SEO Meta Tags -->
<meta name="description" content="Interactive CSS Flexbox Playground - Experiment with flex properties in real-time and learn CSS layout through hands-on practice. Perfect for web developers of all levels.">
<meta name="keywords" content="CSS, Flexbox, CSS Layout, Web Development, Learning Tool, CSS Tutorial">
<meta name="author" content="Yoav Sabag">
<!-- Open Graph Meta Tags -->
<meta property="og:title" content="CSS Flexbox Playground">
<meta property="og:description" content="Interactive tool to learn and experiment with CSS Flexbox properties in real-time">
<meta property="og:type" content="website">
<meta property="og:site_name" content="CSS Flexbox Playground">
<!-- Twitter Card Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="CSS Flexbox Playground">
<meta name="twitter:description" content="Interactive tool to learn and experiment with CSS Flexbox properties in real-time">
<meta name="twitter:creator" content="@yoavsbg">
<!-- Favicon -->
<link rel="icon" type="image/svg+xml" href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect width="100" height="100" rx="20" fill="%233b82f6"/><rect x="20" y="25" width="25" height="50" rx="4" fill="white"/><rect x="55" y="25" width="25" height="50" rx="4" fill="white"/></svg>'>
<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAJZlWElmTU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgExAAIAAAARAAAAWodpAAQAAAABAAAAbAAAAAAAAABgAAAAAQAAAGAAAAABd3d3Lmlua3NjYXBlLm9yZwAAAAOgAQADAAAAAQABAACgAgAEAAAAAQAAACCgAwAEAAAAAQAAACAAAAAA4nPqwQAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAi1pVFh0WE1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6fsvk4SHvW4aMFBGmGGc8wYQqUmOKQyW6nX91YIB8BwIKmSr7LN+QS0v7xiL6IOFxVEFHRLSkzHEwO+8RlN4FgVs7XFAqYTCCn+ck3l/B5vW2/8WcBCGAAAAAElFTkSuQmCC">
<!-- Analytics -->
<script src="https://cdn.counter.dev/script.js" data-id="b70cd8af-bfad-41f3-a30d-198b53a52f3c" data-utcoffset="2"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
:root {
--bg-primary: #f3f4f6;
--bg-secondary: #f9fafb;
--bg-code: #e5e7eb;
--text-primary: #111827;
--text-secondary: #4b5563;
--border-color: #e5e7eb;
--preview-bg: white;
}
[data-theme="dark"] {
--bg-primary: #1f2937;
--bg-secondary: #111827;
--bg-code: #374151;
--text-primary: #f9fafb;
--text-secondary: #d1d5db;
--border-color: #374151;
--preview-bg: #1f2937;
}
/* Base styles */
:root {
--spacing-xs: 0.5rem;
--spacing-sm: 0.75rem;
--spacing-md: 1rem;
--spacing-lg: 1.5rem;
--spacing-xl: 2rem;
}
body {
font-family: system-ui, -apple-system, sans-serif;
margin: 0;
padding: var(--spacing-md);
display: flex;
justify-content: center;
background-color: var(--bg-primary);
color: var(--text-primary);
transition: background-color 0.3s, color 0.3s;
min-height: 100vh;
}
.container {
width: 100%;
max-width: 80rem;
padding: var(--spacing-lg);
background-color: var(--bg-secondary);
border-radius: 0.5rem;
position: relative;
}
.main-content {
display: grid;
grid-template-columns: 1fr 300px;
gap: var(--spacing-xl);
margin-top: var(--spacing-xl);
}
.preview-area {
min-height: 400px;
padding: var(--spacing-md);
background-color: var(--preview-bg);
border: 2px solid var(--border-color);
border-radius: 0.375rem;
transition: background-color 0.3s;
}
.controls {
display: flex;
flex-direction: column;
gap: var(--spacing-md);
}
.control-group {
display: flex;
flex-direction: column;
gap: var(--spacing-xs);
}
select {
padding: var(--spacing-xs) var(--spacing-sm);
border: 1px solid var(--border-color);
border-radius: 0.25rem;
width: 100%;
background-color: var(--preview-bg);
color: var(--text-primary);
}
/* Mobile styles */
@media (max-width: 768px) {
body {
padding: 0;
}
.container {
min-height: 100vh;
padding: var(--spacing-md);
border-radius: 0;
display: flex;
flex-direction: column;
}
.main-content {
grid-template-columns: 1fr;
gap: var(--spacing-md);
margin-top: var(--spacing-md);
flex: 1;
}
.preview-area {
min-height: 180px;
height: 180px;
order: -1;
}
.box {
width: 40px !important;
padding: 15px 8px !important;
margin: 3px !important;
font-size: 0.9rem;
}
.controls-and-code {
display: flex;
flex-direction: column;
gap: var(--spacing-md);
}
.control-group {
margin-bottom: var(--spacing-xs);
}
h1 {
font-size: 1.25rem;
padding-right: 3rem;
margin: 0 0 var(--spacing-xs) 0;
}
.description {
font-size: 0.875rem;
margin: 0;
}
.footer {
margin-top: var(--spacing-md);
padding: var(--spacing-sm) 0;
font-size: 0.875rem;
}
.theme-toggle {
top: var(--spacing-sm);
right: var(--spacing-sm);
}
}
.theme-toggle {
position: absolute;
top: 1rem;
right: 1rem;
padding: 0.5rem;
border-radius: 0.375rem;
border: 1px solid var(--border-color);
background: transparent;
color: var(--text-primary);
cursor: pointer;
display: flex;
align-items: center;
gap: 0.5rem;
transition: border-color 0.3s;
font-size: 1.2rem;
width: 2.5rem;
height: 2.5rem;
justify-content: center;
}
.theme-toggle i {
width: 1.2rem;
height: 1.2rem;
line-height: 1.2rem;
display: flex;
align-items: center;
justify-content: center;
}
.theme-toggle:hover {
border-color: var(--text-secondary);
}
h1 {
font-size: 1.5rem;
font-weight: bold;
margin-bottom: 0.5rem;
padding-right: 3rem;
}
.description {
color: var(--text-secondary);
margin-bottom: 2rem;
}
.controls {
margin-bottom: 2rem;
display: flex;
flex-direction: column;
gap: 1rem;
}
.control-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
label {
font-weight: 500;
}
select {
padding: 0.5rem;
border: 1px solid var(--border-color);
border-radius: 0.25rem;
width: 100%;
max-width: 300px;
background-color: var(--preview-bg);
color: var(--text-primary);
}
.preview-area {
min-height: 400px;
padding: 1rem;
background-color: var(--preview-bg);
border: 2px solid var(--border-color);
border-radius: 0.375rem;
transition: background-color 0.3s;
}
.box {
width: 60px;
padding: 20px 10px;
margin: 5px;
text-align: center;
color: white;
font-weight: bold;
}
.code-container {
position: relative;
margin-top: 1rem;
padding: 1rem;
background-color: var(--bg-code);
border-radius: 0.375rem;
transition: background-color 0.3s;
}
.copy-button {
position: absolute;
top: 0.5rem;
right: 0.5rem;
padding: 0.375rem 0.75rem;
background-color: #3b82f6;
color: white;
border: none;
border-radius: 0.25rem;
cursor: pointer;
transition: background-color 0.2s;
}
.copy-button:hover {
background-color: #2563eb;
}
pre {
margin: 0;
white-space: pre-wrap;
}
code {
font-family: monospace;
color: var(--text-primary);
}
.footer {
margin-top: 2rem;
text-align: center;
color: var(--text-secondary);
}
.footer a {
color: #3b82f6;
text-decoration: none;
}
.footer a:hover {
color: #2563eb;
}
</style>
</head>
<body>
<div class="container">
<button class="theme-toggle" aria-label="Toggle theme">
<i class="fas fa-sun"></i>
<i class="fas fa-moon" style="display: none;"></i>
</button>
<h1>CSS Flexbox Playground</h1>
<p class="description">Experiment with different flex properties to understand how they affect layout. Adjust the controls below to see changes in real-time and copy the generated CSS code.</p>
<div class="main-content">
<div class="preview-area" id="preview">
<div class="box" style="background-color: #3B82F6;">1</div>
<div class="box" style="background-color: #10B981;">2</div>
<div class="box" style="background-color: #F59E0B;">3</div>
<div class="box" style="background-color: #EF4444;">4</div>
<div class="box" style="background-color: #8B5CF6;">5</div>
</div>
<div class="controls-and-code">
<div class="controls">
<div class="control-group">
<label for="flex-direction">flex-direction:</label>
<select id="flex-direction">
<option value="row">row</option>
<option value="column">column</option>
<option value="row-reverse">row-reverse</option>
<option value="column-reverse">column-reverse</option>
</select>
</div>
<div class="control-group">
<label for="justify-content">justify-content:</label>
<select id="justify-content">
<option value="flex-start">flex-start</option>
<option value="center">center</option>
<option value="flex-end">flex-end</option>
<option value="space-between">space-between</option>
<option value="space-around">space-around</option>
</select>
</div>
<div class="control-group">
<label for="align-items">align-items:</label>
<select id="align-items">
<option value="stretch">stretch</option>
<option value="flex-start">flex-start</option>
<option value="center">center</option>
<option value="flex-end">flex-end</option>
<option value="baseline">baseline</option>
</select>
</div>
<div class="control-group">
<label for="flex-wrap">flex-wrap:</label>
<select id="flex-wrap">
<option value="nowrap">nowrap</option>
<option value="wrap">wrap</option>
<option value="wrap-reverse">wrap-reverse</option>
</select>
</div>
</div>
<div class="code-container">
<button class="copy-button" id="copy-button">Copy</button>
<pre><code id="css-code"></code></pre>
</div>
</div>
</div>
<div class="footer">
Made with 💙 by <a href="https://x.com/yoavsbg" target="_blank" rel="noopener noreferrer">Yoav Sabag</a>
• <a href="https://youtube.com/@yoavsbg" target="_blank" rel="noopener noreferrer">YouTube</a>
• <a href="https://github.com/yoavsbg/css-flexbox-playground" target="_blank" rel="noopener noreferrer">GitHub</a>
• <a href="https://counter.dev/dashboard.html?user=yoavsbg&token=QgNGgF5ZO-g%3D" target="_blank" rel="noopener noreferrer">Open analytics</a>
</div>
</div>
<script>
// Get DOM elements
const preview = document.getElementById('preview');
const flexDirection = document.getElementById('flex-direction');
const justifyContent = document.getElementById('justify-content');
const alignItems = document.getElementById('align-items');
const flexWrap = document.getElementById('flex-wrap');
const cssCode = document.getElementById('css-code');
const copyButton = document.getElementById('copy-button');
const themeToggle = document.querySelector('.theme-toggle');
const sunIcon = themeToggle.querySelector('.fa-sun');
const moonIcon = themeToggle.querySelector('.fa-moon');
// Theme handling
let isDarkTheme = true;
function updateTheme() {
document.documentElement.setAttribute('data-theme', isDarkTheme ? 'dark' : 'light');
sunIcon.style.display = isDarkTheme ? 'none' : 'block';
moonIcon.style.display = isDarkTheme ? 'block' : 'none';
}
themeToggle.addEventListener('click', () => {
isDarkTheme = !isDarkTheme;
updateTheme();
});
// Set initial theme
updateTheme();
// Set initial values
flexDirection.value = 'row';
justifyContent.value = 'space-around';
alignItems.value = 'flex-start';
flexWrap.value = 'nowrap';
// Update preview and code
function updateDisplay() {
// Update preview
preview.style.display = 'flex';
preview.style.flexDirection = flexDirection.value;
preview.style.justifyContent = justifyContent.value;
preview.style.alignItems = alignItems.value;
preview.style.flexWrap = flexWrap.value;
// Update code
const code = `.container {
display: flex;
flex-direction: ${flexDirection.value};
justify-content: ${justifyContent.value};
align-items: ${alignItems.value};
flex-wrap: ${flexWrap.value};
}`;
cssCode.textContent = code;
}
// Copy to clipboard
function copyToClipboard() {
const textarea = document.createElement('textarea');
textarea.value = cssCode.textContent;
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
copyButton.textContent = 'Copied!';
setTimeout(() => {
copyButton.textContent = 'Copy';
}, 2000);
}
// Add event listeners
flexDirection.addEventListener('change', updateDisplay);
justifyContent.addEventListener('change', updateDisplay);
alignItems.addEventListener('change', updateDisplay);
flexWrap.addEventListener('change', updateDisplay);
copyButton.addEventListener('click', copyToClipboard);
// Initial display
updateDisplay();
</script>
</body>
</html>