-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss.html
More file actions
1071 lines (943 loc) · 56.9 KB
/
Copy pathcss.html
File metadata and controls
1071 lines (943 loc) · 56.9 KB
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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Cheatsheet</title>
<style>
:root {
--bg: #f7f8fa;
--panel: #ffffff;
--text: #1c1e21;
--muted: #5b6270;
--border: #e2e5ea;
--accent: #9b59b6;
--code-bg: #f0f2f5;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.5;
}
header.page-header { padding: 1.6rem 1.5rem .8rem; text-align: center; }
header.page-header h1 { margin: 0 0 .3rem; font-size: 1.8rem; }
header.page-header p { color: var(--muted); margin: 0 auto; max-width: 640px; }
.sheet-links { margin-top: .6rem; font-size: .85rem; }
.sheet-links a { color: var(--accent); text-decoration: none; margin: 0 .4rem; font-weight: 600; }
.sheet-links a:hover { text-decoration: underline; }
.sheet-links a.current { color: var(--text); text-decoration: underline; }
.live-note {
max-width: 700px; margin: .8rem auto 0; padding: .6rem .9rem;
background: #f6ecfa; border: 1px solid #ddb8ea; border-radius: 8px;
font-size: .8rem; color: #5c2d6b; text-align: center;
}
.search-bar {
position: sticky; top: 0; z-index: 20;
background: var(--bg);
padding: .8rem 1.5rem;
border-bottom: 1px solid var(--border);
}
.search-bar input {
width: 100%; max-width: 700px; display: block; margin: 0 auto;
padding: .65rem .9rem; font-size: 1rem;
border: 2px solid var(--border); border-radius: 10px;
outline: none; background: var(--panel); color: var(--text);
}
.search-bar input:focus { border-color: var(--accent); }
.search-meta { text-align: center; font-size: .78rem; color: var(--muted); margin-top: .35rem; }
nav.toc {
max-width: 1100px; margin: 1rem auto; padding: .8rem 1.2rem;
background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
}
nav.toc ul { display: flex; flex-wrap: wrap; gap: .5rem; list-style: none; padding: 0; margin: 0; }
nav.toc a {
display: inline-block; padding: .3rem .7rem; border-radius: 999px;
background: var(--code-bg); color: var(--accent); text-decoration: none; font-size: .82rem;
}
nav.toc a:hover { background: var(--accent); color: #fff; }
main { max-width: 1100px; margin: 0 auto 3rem; padding: 0 1.2rem; }
section.category {
background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
margin: 1.4rem 0; padding: 1.1rem 1.2rem;
}
section.category h2 { margin: 0 0 .3rem; font-size: 1.2rem; }
section.category .cat-intro {
margin: 0 0 1rem; padding-bottom: .8rem; color: var(--muted); font-size: .85rem;
border-bottom: 2px solid var(--accent);
}
section.category.hidden { display: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: .9rem; }
.cheat-card {
border: 1px solid var(--border); border-radius: 10px; padding: .8rem .9rem .9rem; background: #fdfdfe;
display: flex; flex-direction: column;
}
.cheat-card.hidden { display: none; }
.cheat-card h3 {
margin: 0 0 .35rem; font-size: 1rem;
font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
color: var(--accent);
}
.cheat-card p.desc { margin: 0 0 .55rem; font-size: .82rem; color: var(--text); opacity: .85; }
.micro-label {
font-size: .65rem; text-transform: uppercase; letter-spacing: .06em;
color: var(--muted); font-weight: 700; margin: 0 0 .25rem;
}
.cheat-card pre {
margin: 0 0 .6rem; background: var(--code-bg); padding: .5rem .6rem; border-radius: 6px;
font-size: .74rem; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}
.cheat-card .preview { font-size: .82rem; margin-top: auto; }
.preview-box { border: 1px dashed var(--border); border-radius: 6px; padding: .5rem .6rem; background: #fafbfc; font-size: .8rem; }
code { font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; }
#no-results { text-align: center; color: var(--muted); padding: 2rem; display: none; }
footer.page-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 2rem 0; }
/* --- demo helpers used only inside preview boxes --- */
.demo-box { width: 60px; height: 40px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: .7rem; }
.demo-flex { display: flex; gap: .3rem; border: 1px dashed var(--border); padding: .3rem; }
.demo-flex div { background: var(--accent); color: #fff; padding: .3rem .5rem; font-size: .7rem; border-radius: 4px; }
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; border: 1px dashed var(--border); padding: .3rem; }
.demo-grid div { background: var(--accent); color: #fff; padding: .3rem; font-size: .7rem; text-align: center; border-radius: 4px; }
.demo-stack { position: relative; height: 60px; border: 1px dashed var(--border); }
.demo-stack div { position: absolute; width: 40px; height: 40px; border-radius: 6px; color: #fff; font-size: .65rem; display: flex; align-items: center; justify-content: center; }
.demo-float::after { content: ""; display: table; clear: both; }
.demo-float img.f { float: left; width: 30px; height: 30px; background: var(--accent); border-radius: 4px; margin-right: .4rem; }
</style>
</head>
<body>
<header class="page-header">
<h1>CSS Cheatsheet</h1>
<p>Core CSS concepts, selectors, and properties. Every card renders the property live, so you see exactly what it does, not just what it says.</p>
<div class="sheet-links">
<a href="html.html">HTML</a>·
<a href="css.html" class="current">CSS</a>·
<a href="javascript.html">JavaScript</a>·
<a href="angular.html">Angular</a>
</div>
<div class="live-note">🎨 Boxes labeled <strong>Result</strong> are the actual rendered CSS from the code above them — the browser is drawing it right now, live in this page.</div>
</header>
<div class="search-bar">
<input type="text" id="search" placeholder="Search properties... (e.g. flex, grid, color)" autocomplete="off">
<div class="search-meta" id="search-meta"></div>
</div>
<nav class="toc" aria-label="Table of contents">
<ul>
<li><a href="#syntax">Syntax</a></li>
<li><a href="#selectors">Selectors</a></li>
<li><a href="#box">Box Model</a></li>
<li><a href="#position">Position & Display</a></li>
<li><a href="#flexbox">Flexbox</a></li>
<li><a href="#grid">Grid</a></li>
<li><a href="#typography">Typography & Color</a></li>
<li><a href="#background">Backgrounds & Borders</a></li>
<li><a href="#transitions">Transitions & Animation</a></li>
<li><a href="#transform">Transform</a></li>
<li><a href="#variables">Variables & Functions</a></li>
<li><a href="#media">Media Queries</a></li>
<li><a href="#units">Units</a></li>
</ul>
</nav>
<main>
<!-- ===================== SYNTAX ===================== -->
<section class="category" id="syntax">
<h2>Syntax Basics</h2>
<p class="cat-intro">The minimum grammar every stylesheet is built from.</p>
<div class="grid">
<div class="cheat-card" data-key="rule selector declaration block syntax">
<h3>Rule structure</h3>
<p class="desc">A CSS rule pairs a selector (what to style) with a declaration block (how to style it). Each declaration is a <code>property: value;</code> pair.</p>
<div class="micro-label">Code</div>
<pre>selector {
property: value;
}</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box">Not tied to a real element — this is the general pattern every rule below follows.</div></div>
</div>
<div class="cheat-card" data-key="comment css">
<h3>Comment</h3>
<p class="desc">Notes for humans, ignored by the browser. CSS only has the <code>/* */</code> block form — there's no single-line <code>//</code>.</p>
<div class="micro-label">Code</div>
<pre>/* this explains the rule below */
p { color: red; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box">No visual output — comments are stripped before rendering.</div></div>
</div>
<div class="cheat-card" data-key="link stylesheet external inline style attribute">
<h3>Attaching CSS</h3>
<p class="desc">Three ways to apply CSS to a page: an external file, a <code><style></code> block in the head, or an inline <code>style</code> attribute (highest priority of the three).</p>
<div class="micro-label">Code</div>
<pre><link rel="stylesheet" href="style.css">
<style>p{color:red}</style>
<p style="color:red"></pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box">All three produce identical styling — they differ only in scope and priority.</div></div>
</div>
<div class="cheat-card" data-key="specificity important cascade priority">
<h3>Specificity & !important</h3>
<p class="desc">When two rules target the same element, specificity decides the winner: inline > ID > class/attribute/pseudo-class > element. <code>!important</code> jumps the queue entirely.</p>
<div class="micro-label">Code</div>
<pre>#id { color: blue; }
.class { color: red !important; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="color:#c0392b;font-weight:700">red wins — !important beats the ID rule</div></div>
</div>
</div>
</section>
<!-- ===================== SELECTORS ===================== -->
<section class="category" id="selectors">
<h2>Selectors</h2>
<p class="cat-intro">How a rule chooses which elements it applies to.</p>
<div class="grid">
<div class="cheat-card" data-key="universal selector star all elements">
<h3>* universal</h3>
<p class="desc">Matches every single element on the page. Commonly used in resets to zero out default margins.</p>
<div class="micro-label">Code</div>
<pre>* { margin: 0; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box">Applies to everything — used sparingly, since it's easy to overreach.</div></div>
</div>
<div class="cheat-card" data-key="type selector element tag">
<h3>p element</h3>
<p class="desc">A bare tag name selects every element of that type. The lowest-specificity selector, easily overridden by class or ID rules.</p>
<div class="micro-label">Code</div>
<pre>p { color: navy; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><p style="color:navy;margin:0">every <p> turns navy</p></div>
</div>
<div class="cheat-card" data-key="class selector dot">
<h3>.class</h3>
<p class="desc">Selects every element carrying a given class attribute. The most common selector for reusable styling.</p>
<div class="micro-label">Code</div>
<pre>.badge { padding: .2rem .5rem; border-radius: 999px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="padding:.2rem .5rem;border-radius:999px;background:var(--accent);color:#fff;font-size:.75rem">badge</span></div>
</div>
<div class="cheat-card" data-key="id selector hash">
<h3>#id</h3>
<p class="desc">Selects the one element carrying a given <code>id</code> — ids must be unique per page, so this always targets a single element.</p>
<div class="micro-label">Code</div>
<pre>#header { background: #eef; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div id="css-demo-header" style="background:#eef;padding:.3rem .5rem;border-radius:4px">#header element</div></div>
</div>
<div class="cheat-card" data-key="attribute selector square brackets">
<h3>[attr]</h3>
<p class="desc">Selects elements that carry a given HTML attribute, optionally requiring a specific value.</p>
<div class="micro-label">Code</div>
<pre>input[type="text"] { border: 2px solid #9b59b6; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><input type="text" placeholder="matches" style="border:2px solid #9b59b6;padding:.2rem .4rem;width:110px"></div>
</div>
<div class="cheat-card" data-key="descendant combinator space">
<h3>A B descendant</h3>
<p class="desc">A space between two selectors matches B anywhere inside A, at any nesting depth — not just direct children.</p>
<div class="micro-label">Code</div>
<pre>.box em { color: #9b59b6; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box">Any <em style="color:#9b59b6">emphasis</em>, however deeply nested inside</div></div>
</div>
<div class="cheat-card" data-key="child combinator direct greater than">
<h3>A > B child</h3>
<p class="desc">The <code>></code> combinator matches B only when it's a <em>direct</em> child of A — grandchildren don't count.</p>
<div class="micro-label">Code</div>
<pre>ul > li { list-style: none; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><ul style="margin:0;padding-left:0;list-style:none;font-size:.8rem"><li>direct child — no bullet</li></ul></div>
</div>
<div class="cheat-card" data-key="adjacent sibling combinator plus">
<h3>A + B adjacent sibling</h3>
<p class="desc">Matches B only when it comes immediately after A as a sibling — useful for spacing the element right after a heading.</p>
<div class="micro-label">Code</div>
<pre>h4 + p { margin-top: 0; color: #9b59b6; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box"><h4 style="margin:0 0 .2rem">Heading</h4><p style="margin:0;color:#9b59b6">right after it — styled</p></div></div>
</div>
<div class="cheat-card" data-key="general sibling combinator tilde">
<h3>A ~ B general sibling</h3>
<p class="desc">Matches every B sibling that comes after A, not just the immediately adjacent one.</p>
<div class="micro-label">Code</div>
<pre>h4 ~ p { color: gray; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box"><h4 style="margin:0 0 .2rem">Heading</h4><p style="margin:0;color:gray">gray</p><p style="margin:0;color:gray">gray too</p></div></div>
</div>
<div class="cheat-card" data-key="grouping selector comma multiple">
<h3>A, B grouping</h3>
<p class="desc">A comma applies the same declaration block to several unrelated selectors at once, avoiding repetition.</p>
<div class="micro-label">Code</div>
<pre>h5, strong { color: #9b59b6; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box"><h5 style="margin:0;color:#9b59b6">heading</h5><strong style="color:#9b59b6">and bold text</strong></div></div>
</div>
<div class="cheat-card" data-key="pseudo class hover focus state">
<h3>:hover / :focus</h3>
<p class="desc">Pseudo-classes match a temporary state rather than a fixed part of the DOM — mouse hover, keyboard focus, checked state, and more.</p>
<div class="micro-label">Code</div>
<pre>button:hover { background: #9b59b6; color: #fff; }</pre>
<div class="micro-label">Result — hover it</div>
<div class="preview"><button type="button" style="transition:background .15s" onmouseover="this.style.background='#9b59b6';this.style.color='#fff'" onmouseout="this.style.background='';this.style.color=''">Hover me</button></div>
</div>
<div class="cheat-card" data-key="pseudo class nth child structural">
<h3>:nth-child()</h3>
<p class="desc">Selects elements by their numeric position among siblings — accepts a number, or a formula like <code>2n</code> for every second item.</p>
<div class="micro-label">Code</div>
<pre>li:nth-child(2) { color: red; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><ul style="margin:0;padding-left:1.1em;font-size:.8rem"><li>one</li><li style="color:red">two ← nth-child(2)</li><li>three</li></ul></div>
</div>
<div class="cheat-card" data-key="pseudo class first last child not">
<h3>:first-child / :last-child / :not()</h3>
<p class="desc">Matches structural extremes, or excludes elements that match another selector inside <code>:not()</code>.</p>
<div class="micro-label">Code</div>
<pre>li:not(:last-child) { border-bottom: 1px solid #ddd; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><ul style="margin:0;padding-left:1.1em;font-size:.8rem"><li style="border-bottom:1px solid #ddd">one</li><li style="border-bottom:1px solid #ddd">two</li><li>three — no border</li></ul></div>
</div>
<div class="cheat-card" data-key="pseudo element before after content">
<h3>::before / ::after</h3>
<p class="desc">Inserts generated content immediately before or after an element's real content, controlled entirely by the <code>content</code> property.</p>
<div class="micro-label">Code</div>
<pre>.tag::before { content: "#"; color: #9b59b6; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><style>.css-demo-hash::before{content:"#";color:#9b59b6;font-weight:700}</style><span class="preview-box css-demo-hash">css</span></div>
</div>
</div>
</section>
<!-- ===================== BOX MODEL ===================== -->
<section class="category" id="box">
<h2>Box Model</h2>
<p class="cat-intro">Every element is a rectangular box made of content, padding, border, and margin, from the inside out.</p>
<div class="grid">
<div class="cheat-card" data-key="width height size element">
<h3>width / height</h3>
<p class="desc">Sets the size of the content box directly. Percentages resolve against the size of the containing element.</p>
<div class="micro-label">Code</div>
<pre>.box { width: 80px; height: 30px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box demo-box" style="width:80px;height:30px">80×30</div></div>
</div>
<div class="cheat-card" data-key="margin outer spacing">
<h3>margin</h3>
<p class="desc">Transparent space outside the border, pushing neighboring elements away. Vertical margins between block elements can collapse into a single gap.</p>
<div class="micro-label">Code</div>
<pre>.box { margin: 10px 20px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="padding:0"><div class="demo-box" style="margin:8px auto">margin: 8px auto</div></div></div>
</div>
<div class="cheat-card" data-key="padding inner spacing">
<h3>padding</h3>
<p class="desc">Space inside the border, between the border and the content — increases the element's visual size unless <code>box-sizing: border-box</code> is set.</p>
<div class="micro-label">Code</div>
<pre>.box { padding: 10px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-box" style="padding:10px;width:auto">padded</div></div>
</div>
<div class="cheat-card" data-key="border outline">
<h3>border</h3>
<p class="desc">Draws a visible line at the edge of the padding, between padding and margin. Shorthand for width, style, and color.</p>
<div class="micro-label">Code</div>
<pre>.box { border: 2px solid #333; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="border:2px solid #333">bordered</div></div>
</div>
<div class="cheat-card" data-key="box sizing border-box content-box">
<h3>box-sizing</h3>
<p class="desc">Controls whether <code>width</code>/<code>height</code> include padding and border (<code>border-box</code>) or exclude them (<code>content-box</code>, the default). Both boxes below have <code>width: 100px</code>.</p>
<div class="micro-label">Code</div>
<pre>.a { box-sizing: content-box; width: 100px; padding: 10px; }
.b { box-sizing: border-box; width: 100px; padding: 10px; }</pre>
<div class="micro-label">Result</div>
<div class="preview">
<div style="display:flex;gap:.4rem;align-items:flex-start">
<div style="box-sizing:content-box;width:100px;padding:10px;background:var(--accent);color:#fff;font-size:.65rem">content-box: 120px total</div>
<div style="box-sizing:border-box;width:100px;padding:10px;background:#2f6fd6;color:#fff;font-size:.65rem">border-box: 100px total</div>
</div>
</div>
</div>
<div class="cheat-card" data-key="overflow scroll hidden visible clip">
<h3>overflow</h3>
<p class="desc">Controls what happens when content is bigger than its box: <code>visible</code> (default, spills out), <code>hidden</code> (clipped), <code>scroll</code>/<code>auto</code> (scrollbars).</p>
<div class="micro-label">Code</div>
<pre>.box { overflow: auto; height: 30px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="width:100px;height:30px;overflow:auto">This text is much longer than the box, so it scrolls.</div></div>
</div>
</div>
</section>
<!-- ===================== POSITION & DISPLAY ===================== -->
<section class="category" id="position">
<h2>Position & Display</h2>
<p class="cat-intro">How an element participates in layout, and how it can be pulled out of the normal document flow.</p>
<div class="grid">
<div class="cheat-card" data-key="display block inline none flex grid">
<h3>display</h3>
<p class="desc">The most fundamental layout property. <code>block</code> stacks vertically, <code>inline</code> flows with text, <code>none</code> removes the element from layout entirely.</p>
<div class="micro-label">Code</div>
<pre>span.as-block { display: block; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box"><span style="display:block;background:var(--accent);color:#fff;padding:.15rem .3rem;margin-bottom:.2rem">block span</span><span style="background:var(--accent);color:#fff;padding:.15rem .3rem">inline span</span></div></div>
</div>
<div class="cheat-card" data-key="position static relative absolute fixed sticky">
<h3>position</h3>
<p class="desc"><code>relative</code> offsets an element from its normal spot; <code>absolute</code> positions it against its nearest positioned ancestor; <code>fixed</code> pins it to the viewport.</p>
<div class="micro-label">Code</div>
<pre>.parent { position: relative; }
.badge { position: absolute; top: 2px; right: 2px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="position:relative;height:44px">parent box<span style="position:absolute;top:2px;right:2px;background:var(--accent);color:#fff;font-size:.65rem;padding:0 .3rem;border-radius:3px">abs</span></div></div>
</div>
<div class="cheat-card" data-key="top right bottom left offset">
<h3>top / right / bottom / left</h3>
<p class="desc">Offsets a <code>relative</code>, <code>absolute</code>, <code>fixed</code>, or <code>sticky</code> element from its reference edge. Ignored entirely on <code>static</code> elements.</p>
<div class="micro-label">Code</div>
<pre>.box { position: relative; top: 8px; left: 8px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="height:44px"><div class="demo-box" style="position:relative;top:6px;left:6px;width:50px;height:24px">offset</div></div></div>
</div>
<div class="cheat-card" data-key="z-index stack order layer overlap">
<h3>z-index</h3>
<p class="desc">Controls which positioned element sits on top when two overlap. Only has an effect on elements with a <code>position</code> other than <code>static</code>.</p>
<div class="micro-label">Code</div>
<pre>.back { z-index: 1; }
.front { z-index: 2; }</pre>
<div class="micro-label">Result</div>
<div class="preview">
<div class="demo-stack">
<div style="left:10px;top:8px;background:#2f6fd6;z-index:1">z:1</div>
<div style="left:30px;top:16px;background:var(--accent);z-index:2">z:2</div>
</div>
</div>
</div>
<div class="cheat-card" data-key="float clear legacy layout wrap text">
<h3>float / clear</h3>
<p class="desc">Pulls an element to one side and lets inline content wrap around it — the pre-Flexbox way to do text-wraps-image layouts. <code>clear</code> stops that wrapping.</p>
<div class="micro-label">Code</div>
<pre>.thumb { float: left; margin-right: 8px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box demo-float"><span class="f" style="display:inline-block"></span>Text wraps around the floated box on its left, like a magazine layout.</div></div>
</div>
<div class="cheat-card" data-key="visibility hidden collapse space">
<h3>visibility</h3>
<p class="desc">Hides an element visually while still reserving its layout space — unlike <code>display: none</code>, which removes the space too.</p>
<div class="micro-label">Code</div>
<pre>.ghost { visibility: hidden; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="display:flex;gap:.3rem"><span>before</span><span style="visibility:hidden">[hidden but still takes space]</span><span>after</span></div></div>
</div>
</div>
</section>
<!-- ===================== FLEXBOX ===================== -->
<section class="category" id="flexbox">
<h2>Flexbox</h2>
<p class="cat-intro">A one-dimensional layout system for distributing space among items in a row or column.</p>
<div class="grid">
<div class="cheat-card" data-key="display flex container row">
<h3>display: flex</h3>
<p class="desc">Turns an element into a flex container, laying its direct children out in a row by default and enabling the rest of the flex properties.</p>
<div class="micro-label">Code</div>
<pre>.row { display: flex; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-flex"><div>a</div><div>b</div><div>c</div></div></div>
</div>
<div class="cheat-card" data-key="flex-direction row column reverse main axis">
<h3>flex-direction</h3>
<p class="desc">Sets the main axis: <code>row</code> (default), <code>column</code>, or their reversed variants.</p>
<div class="micro-label">Code</div>
<pre>.row { flex-direction: column; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-flex" style="flex-direction:column;width:60px"><div>a</div><div>b</div></div></div>
</div>
<div class="cheat-card" data-key="justify-content main axis alignment space-between center">
<h3>justify-content</h3>
<p class="desc">Aligns items along the main axis — spreads, centers, or packs them, e.g. <code>center</code>, <code>space-between</code>, <code>flex-end</code>.</p>
<div class="micro-label">Code</div>
<pre>.row { justify-content: space-between; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-flex" style="justify-content:space-between"><div>a</div><div>b</div></div></div>
</div>
<div class="cheat-card" data-key="align-items cross axis alignment center stretch">
<h3>align-items</h3>
<p class="desc">Aligns items along the cross axis (perpendicular to the main axis) — e.g. <code>center</code>, <code>flex-start</code>, <code>stretch</code> (default).</p>
<div class="micro-label">Code</div>
<pre>.row { align-items: center; height: 50px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-flex" style="align-items:center;height:50px"><div>centered</div></div></div>
</div>
<div class="cheat-card" data-key="flex-wrap nowrap wrap multiple lines">
<h3>flex-wrap</h3>
<p class="desc">Controls whether items are forced onto one line (default, may overflow) or allowed to wrap onto multiple lines.</p>
<div class="micro-label">Code</div>
<pre>.row { flex-wrap: wrap; width: 90px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-flex" style="flex-wrap:wrap;width:90px"><div>a</div><div>b</div><div>c</div><div>d</div></div></div>
</div>
<div class="cheat-card" data-key="gap spacing between flex grid items">
<h3>gap</h3>
<p class="desc">Adds consistent space between flex or grid items, without the double-margin math that older layouts needed.</p>
<div class="micro-label">Code</div>
<pre>.row { display: flex; gap: 10px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-flex" style="gap:10px"><div>a</div><div>b</div></div></div>
</div>
<div class="cheat-card" data-key="flex grow shrink basis item sizing">
<h3>flex (grow shrink basis)</h3>
<p class="desc">Shorthand controlling how a flex item grows or shrinks relative to its siblings. <code>flex: 1</code> means "take up all remaining space".</p>
<div class="micro-label">Code</div>
<pre>.item { flex: 1; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-flex"><div style="flex:1">flex: 1 (grows)</div><div>fixed</div></div></div>
</div>
</div>
</section>
<!-- ===================== GRID ===================== -->
<section class="category" id="grid">
<h2>Grid</h2>
<p class="cat-intro">A two-dimensional layout system for arranging items into rows and columns at once.</p>
<div class="grid">
<div class="cheat-card" data-key="display grid container two dimensional">
<h3>display: grid</h3>
<p class="desc">Turns an element into a grid container. Without explicit columns, children auto-place into a single column.</p>
<div class="micro-label">Code</div>
<pre>.layout { display: grid; grid-template-columns: 1fr 1fr; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-grid"><div>1</div><div>2</div><div>3</div><div>4</div></div></div>
</div>
<div class="cheat-card" data-key="grid-template-columns rows track sizing">
<h3>grid-template-columns</h3>
<p class="desc">Defines how many column tracks exist and how wide each one is — fixed sizes, percentages, or the flexible <code>fr</code> unit.</p>
<div class="micro-label">Code</div>
<pre>.layout { grid-template-columns: 1fr 2fr; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-grid" style="grid-template-columns:1fr 2fr"><div>1fr</div><div>2fr (wider)</div></div></div>
</div>
<div class="cheat-card" data-key="grid-gap row-gap column-gap">
<h3>gap</h3>
<p class="desc">Sets the space between grid rows and columns in one declaration (or separately via <code>row-gap</code>/<code>column-gap</code>).</p>
<div class="micro-label">Code</div>
<pre>.layout { gap: 10px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-grid" style="gap:10px"><div>1</div><div>2</div></div></div>
</div>
<div class="cheat-card" data-key="grid-column grid-row item placement span">
<h3>grid-column / grid-row</h3>
<p class="desc">Places or stretches an individual item across specific track lines — <code>1 / 3</code> means "start at line 1, end at line 3".</p>
<div class="micro-label">Code</div>
<pre>.item { grid-column: 1 / 3; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-grid"><div style="grid-column:1/3">spans both columns</div></div></div>
</div>
<div class="cheat-card" data-key="grid-template-areas named layout regions">
<h3>grid-template-areas</h3>
<p class="desc">Names layout regions as a visual ASCII map, then places items into them by name via <code>grid-area</code> — very readable for page layouts.</p>
<div class="micro-label">Code</div>
<pre>.layout {
grid-template-areas:
"header header"
"nav main";
}</pre>
<div class="micro-label">Result</div>
<div class="preview">
<div style="display:grid;grid-template-areas:'h h' 'n m';grid-template-columns:1fr 2fr;gap:3px;font-size:.65rem">
<div style="grid-area:h;background:var(--accent);color:#fff;padding:.3rem;text-align:center">header</div>
<div style="grid-area:n;background:#2f6fd6;color:#fff;padding:.3rem;text-align:center">nav</div>
<div style="grid-area:m;background:#1e8449;color:#fff;padding:.3rem;text-align:center">main</div>
</div>
</div>
</div>
<div class="cheat-card" data-key="repeat auto-fill auto-fit minmax function responsive">
<h3>repeat() / minmax()</h3>
<p class="desc">Generates repeated tracks without listing each one, and <code>minmax()</code> lets each track flex between a floor and ceiling size — the classic responsive card-grid recipe.</p>
<div class="micro-label">Code</div>
<pre>grid-template-columns: repeat(3, minmax(40px, 1fr));</pre>
<div class="micro-label">Result</div>
<div class="preview"><div style="display:grid;grid-template-columns:repeat(3, minmax(40px, 1fr));gap:4px"><div class="demo-box" style="width:auto;height:24px">1</div><div class="demo-box" style="width:auto;height:24px">2</div><div class="demo-box" style="width:auto;height:24px">3</div></div></div>
</div>
</div>
</section>
<!-- ===================== TYPOGRAPHY & COLOR ===================== -->
<section class="category" id="typography">
<h2>Typography & Color</h2>
<p class="cat-intro">Properties that control how text and color look on the page.</p>
<div class="grid">
<div class="cheat-card" data-key="color text foreground">
<h3>color</h3>
<p class="desc">Sets the foreground (text) color of an element — also affects things like the default border color of form controls in some browsers.</p>
<div class="micro-label">Code</div>
<pre>p { color: #9b59b6; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="color:#9b59b6">colored text</span></div>
</div>
<div class="cheat-card" data-key="font-family typeface stack fallback">
<h3>font-family</h3>
<p class="desc">Sets the typeface, listing fallbacks in order in case earlier fonts aren't installed or don't load.</p>
<div class="micro-label">Code</div>
<pre>body { font-family: Georgia, serif; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="font-family:Georgia, serif">A serif typeface preview</div></div>
</div>
<div class="cheat-card" data-key="font-size text size scale">
<h3>font-size</h3>
<p class="desc">Sets the size of text. <code>rem</code> units are usually preferred so text scales consistently with the user's root font-size settings.</p>
<div class="micro-label">Code</div>
<pre>h1 { font-size: 1.4rem; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="font-size:1.4rem">Larger text</span></div>
</div>
<div class="cheat-card" data-key="font-weight bold thin numeric">
<h3>font-weight</h3>
<p class="desc">Sets text thickness, from 100 (thin) to 900 (black), or the keywords <code>normal</code>/<code>bold</code>. Not every weight exists in every font.</p>
<div class="micro-label">Code</div>
<pre>b { font-weight: 700; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="font-weight:700">bold text</span> vs <span style="font-weight:300">light text</span></div>
</div>
<div class="cheat-card" data-key="text-align left center right justify">
<h3>text-align</h3>
<p class="desc">Horizontally aligns inline content within its block container: <code>left</code>, <code>center</code>, <code>right</code>, or <code>justify</code>.</p>
<div class="micro-label">Code</div>
<pre>p { text-align: center; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="text-align:center">centered text</div></div>
</div>
<div class="cheat-card" data-key="line-height leading spacing readability">
<h3>line-height</h3>
<p class="desc">Sets the vertical space a line of text occupies. Unitless values (like <code>1.6</code>) scale with the element's own font-size and are usually the safest choice.</p>
<div class="micro-label">Code</div>
<pre>p { line-height: 1.8; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="line-height:1.8">Line one<br>Line two</div></div>
</div>
<div class="cheat-card" data-key="letter-spacing tracking characters">
<h3>letter-spacing</h3>
<p class="desc">Adjusts the horizontal space between characters — small positive values are often used for uppercase labels and headings.</p>
<div class="micro-label">Code</div>
<pre>h1 { letter-spacing: .15em; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="letter-spacing:.15em">spaced out</span></div>
</div>
<div class="cheat-card" data-key="text-decoration underline strike overline link">
<h3>text-decoration</h3>
<p class="desc">Adds or removes underline, overline, or strikethrough lines on text — commonly used to remove the default underline from links.</p>
<div class="micro-label">Code</div>
<pre>a { text-decoration: none; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="text-decoration:underline">underlined</span> / <span style="text-decoration:line-through">struck through</span></div>
</div>
<div class="cheat-card" data-key="text-transform uppercase lowercase capitalize casing">
<h3>text-transform</h3>
<p class="desc">Changes the displayed letter casing without altering the actual text content in the HTML source — good for consistent label styling.</p>
<div class="micro-label">Code</div>
<pre>.label { text-transform: uppercase; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="text-transform:uppercase;letter-spacing:.05em">shout this</span></div>
</div>
<div class="cheat-card" data-key="opacity transparency alpha fade">
<h3>opacity</h3>
<p class="desc">Fades the entire element — including its children — uniformly, from fully transparent (<code>0</code>) to fully opaque (<code>1</code>).</p>
<div class="micro-label">Code</div>
<pre>.ghost { opacity: .5; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="opacity:1">full</span> vs <span style="opacity:.5">opacity: .5</span></div>
</div>
<div class="cheat-card" data-key="rgb rgba hsl hex color formats notation">
<h3>Color formats</h3>
<p class="desc">The same color can be written as hex, <code>rgb()</code>/<code>rgba()</code> (with alpha), or <code>hsl()</code>/<code>hsla()</code> (hue, saturation, lightness) — pick whichever is easiest to reason about.</p>
<div class="micro-label">Code</div>
<pre>#ff0000
rgb(255 0 0 / 60%)
hsl(0 100% 50%)</pre>
<div class="micro-label">Result</div>
<div class="preview">
<div style="display:flex;gap:.3rem">
<div style="width:34px;height:24px;background:#ff0000;border-radius:4px"></div>
<div style="width:34px;height:24px;background:rgb(255 0 0 / 60%);border-radius:4px"></div>
<div style="width:34px;height:24px;background:hsl(0 100% 50%);border-radius:4px"></div>
</div>
</div>
</div>
</div>
</section>
<!-- ===================== BACKGROUNDS & BORDERS ===================== -->
<section class="category" id="background">
<h2>Backgrounds & Borders</h2>
<p class="cat-intro">Filling and framing the space behind and around an element.</p>
<div class="grid">
<div class="cheat-card" data-key="background-color fill solid">
<h3>background-color</h3>
<p class="desc">Fills the element's padding and content area with a solid color, sitting behind any background image.</p>
<div class="micro-label">Code</div>
<pre>.box { background-color: #eef; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="background:#eef">filled</div></div>
</div>
<div class="cheat-card" data-key="background-image url gradient linear">
<h3>background-image</h3>
<p class="desc">Sets an image or a CSS gradient as the background. Gradients are drawn entirely by CSS — no image file required.</p>
<div class="micro-label">Code</div>
<pre>.box { background-image: linear-gradient(90deg, #9b59b6, #4f8ef7); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="background-image:linear-gradient(90deg,#9b59b6,#2f6fd6);color:#fff">gradient</div></div>
</div>
<div class="cheat-card" data-key="border-radius rounded corners">
<h3>border-radius</h3>
<p class="desc">Rounds the corners of an element's box. A value of 50% on a square element produces a perfect circle.</p>
<div class="micro-label">Code</div>
<pre>.box { border-radius: 10px; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-box" style="border-radius:10px">round</div></div>
</div>
<div class="cheat-card" data-key="box-shadow drop shadow elevation">
<h3>box-shadow</h3>
<p class="desc">Draws a drop shadow around the element's box — offset-x, offset-y, blur radius, then color. A common way to suggest elevation.</p>
<div class="micro-label">Code</div>
<pre>.card { box-shadow: 0 2px 8px rgba(0,0,0,.25); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="box-shadow:0 2px 8px rgba(0,0,0,.25)">shadow</div></div>
</div>
<div class="cheat-card" data-key="text-shadow glow outline text">
<h3>text-shadow</h3>
<p class="desc">Adds one or more shadows behind text characters — same offset/blur/color syntax as <code>box-shadow</code>, but for glyphs.</p>
<div class="micro-label">Code</div>
<pre>h1 { text-shadow: 1px 1px 2px gray; }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="text-shadow:1px 1px 2px gray;font-size:1.1rem">shadowed</span></div>
</div>
</div>
</section>
<!-- ===================== TRANSITIONS & ANIMATION ===================== -->
<section class="category" id="transitions">
<h2>Transitions & Animation</h2>
<p class="cat-intro">Making property changes happen smoothly over time instead of instantly.</p>
<div class="grid">
<div class="cheat-card" data-key="transition smooth animate property change hover">
<h3>transition</h3>
<p class="desc">Animates a property smoothly between its old and new value whenever it changes — e.g. on <code>:hover</code>. Specify which property, how long, and the easing curve.</p>
<div class="micro-label">Code</div>
<pre>.btn { transition: background .2s ease; }
.btn:hover { background: #333; }</pre>
<div class="micro-label">Result — hover it</div>
<div class="preview"><button type="button" style="transition:background .2s ease" onmouseover="this.style.background='#9b59b6';this.style.color='#fff'" onmouseout="this.style.background='';this.style.color=''">hover me</button></div>
</div>
<div class="cheat-card" data-key="animation keyframes loop infinite spin">
<h3>animation / @keyframes</h3>
<p class="desc"><code>@keyframes</code> defines the steps of a multi-stage animation by name; <code>animation</code> plays it — looping, timing, and direction are all configurable.</p>
<div class="micro-label">Code</div>
<pre>@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 2s linear infinite; }</pre>
<div class="micro-label">Result — running continuously</div>
<div class="preview">
<style>@keyframes demo-spin { to { transform: rotate(360deg); } }</style>
<div class="demo-box" style="animation:demo-spin 2s linear infinite;border-radius:50%">↻</div>
</div>
</div>
<div class="cheat-card" data-key="animation-timing-function easing curve ease-in-out">
<h3>timing function</h3>
<p class="desc">The easing curve used by <code>transition</code> or <code>animation</code> — <code>ease</code> starts fast then slows, <code>linear</code> is constant speed, <code>cubic-bezier()</code> is fully custom.</p>
<div class="micro-label">Code</div>
<pre>transition-timing-function: ease-in-out;</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box">ease · linear · ease-in-out · cubic-bezier(...)</div></div>
</div>
</div>
</section>
<!-- ===================== TRANSFORM ===================== -->
<section class="category" id="transform">
<h2>Transform</h2>
<p class="cat-intro">Moving, rotating, resizing, or skewing an element visually without affecting the layout around it.</p>
<div class="grid">
<div class="cheat-card" data-key="transform translate move position offset">
<h3>translate()</h3>
<p class="desc">Shifts an element by a given distance without affecting where surrounding elements think it is — often smoother than animating <code>top</code>/<code>left</code>.</p>
<div class="micro-label">Code</div>
<pre>.box { transform: translate(10px, 6px); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-box" style="transform:translate(10px,6px)">moved</div></div>
</div>
<div class="cheat-card" data-key="transform rotate degrees spin">
<h3>rotate()</h3>
<p class="desc">Rotates an element around its transform origin (the center, by default) by the given angle.</p>
<div class="micro-label">Code</div>
<pre>.box { transform: rotate(12deg); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-box" style="transform:rotate(12deg)">rotate</div></div>
</div>
<div class="cheat-card" data-key="transform scale grow shrink resize">
<h3>scale()</h3>
<p class="desc">Resizes an element visually by a multiplier, without changing the space it reserves in the layout.</p>
<div class="micro-label">Code</div>
<pre>.box { transform: scale(1.2); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-box" style="transform:scale(1.15)">scale</div></div>
</div>
<div class="cheat-card" data-key="transform skew slant angle">
<h3>skew()</h3>
<p class="desc">Slants an element along the X and/or Y axis by an angle, distorting its shape into a parallelogram.</p>
<div class="micro-label">Code</div>
<pre>.box { transform: skewX(10deg); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="demo-box" style="transform:skewX(10deg)">skew</div></div>
</div>
</div>
</section>
<!-- ===================== VARIABLES & FUNCTIONS ===================== -->
<section class="category" id="variables">
<h2>Variables & Functions</h2>
<p class="cat-intro">CSS's own programmable values, for reuse and responsive math.</p>
<div class="grid">
<div class="cheat-card" data-key="custom property css variable var theme">
<h3>Custom properties (variables)</h3>
<p class="desc">Reusable values defined with a <code>--name</code> and read with <code>var()</code> — the foundation of theming and dark-mode switches in plain CSS.</p>
<div class="micro-label">Code</div>
<pre>:root { --accent: #9b59b6; }
.btn { color: var(--accent); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="color:var(--accent);font-weight:700">styled via var(--accent)</span></div>
</div>
<div class="cheat-card" data-key="calc function math expression mixed units">
<h3>calc()</h3>
<p class="desc">Performs math directly in a CSS value, and can freely mix units — like subtracting a fixed pixel gutter from a percentage width.</p>
<div class="micro-label">Code</div>
<pre>.box { width: calc(100% - 40px); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div style="width:calc(100% - 40px);background:var(--accent);color:#fff;padding:.3rem;font-size:.7rem;border-radius:4px">width: calc(100% - 40px)</div></div>
</div>
<div class="cheat-card" data-key="clamp min max preferred responsive fluid">
<h3>clamp()</h3>
<p class="desc">Takes a minimum, a preferred (often viewport-relative) value, and a maximum — the value never goes outside that range. Great for fluid font sizes.</p>
<div class="micro-label">Code</div>
<pre>h1 { font-size: clamp(1rem, 4vw, 1.8rem); }</pre>
<div class="micro-label">Result — resize the window to see it change</div>
<div class="preview"><span style="font-size:clamp(1rem, 4vw, 1.8rem)">Fluid heading</span></div>
</div>
<div class="cheat-card" data-key="min max function css smallest largest">
<h3>min() / max()</h3>
<p class="desc">Picks the smallest or largest of a comma-separated list of values — e.g. capping a width at a fixed size while still allowing it to shrink.</p>
<div class="micro-label">Code</div>
<pre>.box { width: min(90%, 220px); }</pre>
<div class="micro-label">Result</div>
<div class="preview"><div style="width:min(90%, 220px);background:var(--accent);color:#fff;padding:.3rem;font-size:.7rem;border-radius:4px">width: min(90%, 220px)</div></div>
</div>
</div>
</section>
<!-- ===================== MEDIA QUERIES ===================== -->
<section class="category" id="media">
<h2>Media Queries & Responsive</h2>
<p class="cat-intro">Adapting layout to the viewport size or the user's system preferences. These depend on your actual window/OS settings, so they can't be faked inside a single fixed-size card.</p>
<div class="grid">
<div class="cheat-card" data-key="media query breakpoint responsive min-width">
<h3>@media</h3>
<p class="desc">Wraps a block of rules so they only apply when a condition — most often viewport width — is met. The basis of responsive design.</p>
<div class="micro-label">Code</div>
<pre>@media (min-width: 768px) {
.sidebar { display: block; }
}</pre>
<div class="preview"><div class="preview-box">Try shrinking this browser window — real sites use this to hide/reflow content below a breakpoint.</div></div>
</div>
<div class="cheat-card" data-key="prefers-color-scheme dark mode light system">
<h3>prefers-color-scheme</h3>
<p class="desc">Detects whether the user's OS/browser is set to light or dark mode, so a site can adapt automatically without a manual toggle.</p>
<div class="micro-label">Code</div>
<pre>@media (prefers-color-scheme: dark) {
body { background: #111; color: #eee; }
}</pre>
<div class="preview"><div class="preview-box">Switch your OS theme and reload a dark-mode-aware site to see this fire.</div></div>
</div>
<div class="cheat-card" data-key="viewport meta responsive scale mobile">
<h3>viewport meta tag</h3>
<p class="desc">Not CSS itself, but required in the HTML <code><head></code> for media queries to work sensibly on mobile — without it, phones fake a desktop-width viewport.</p>
<div class="micro-label">Code</div>
<pre><meta name="viewport" content="width=device-width, initial-scale=1"></pre>
<div class="preview"><div class="preview-box">This exact page includes it — that's why it's readable on a phone.</div></div>
</div>
</div>
</section>
<!-- ===================== UNITS ===================== -->
<section class="category" id="units">
<h2>Units</h2>
<p class="cat-intro">The measurement systems CSS values are expressed in — choosing the right one keeps layouts predictable.</p>
<div class="grid">
<div class="cheat-card" data-key="px pixel absolute unit fixed">
<h3>px</h3>
<p class="desc">An absolute, fixed-size unit — doesn't scale with the user's font-size preferences, which makes it a poor choice for text.</p>
<div class="micro-label">Code</div>
<pre>border-width: 2px;</pre>
<div class="micro-label">Result</div>
<div class="preview"><div class="preview-box" style="border:2px solid var(--accent);display:inline-block;padding:.2rem .4rem">2px border, always 2px</div></div>
</div>
<div class="cheat-card" data-key="rem root em relative font size unit scalable">
<h3>rem</h3>
<p class="desc">Relative to the root (<code><html></code>) font-size, so it scales predictably even inside deeply nested components. The recommended default for spacing and font sizes.</p>
<div class="micro-label">Code</div>
<pre>font-size: 1.2rem;</pre>
<div class="micro-label">Result</div>
<div class="preview"><span style="font-size:1.2rem">1.2rem text</span></div>
</div>
<div class="cheat-card" data-key="em relative parent font size unit compounding">
<h3>em</h3>
<p class="desc">Relative to the <em>parent</em> element's font-size, so nested <code>em</code> values compound — powerful, but can surprise you in deep nesting.</p>
<div class="micro-label">Code</div>
<pre>padding: 1.5em;</pre>
<div class="micro-label">Result</div>
<div class="preview"><div style="font-size:.8rem;padding:1.5em;background:var(--accent);color:#fff;display:inline-block;border-radius:4px">1.5em padding</div></div>
</div>
<div class="cheat-card" data-key="percent percentage relative parent size">
<h3>%</h3>
<p class="desc">Relative to a reference value from the parent — usually its width for horizontal properties, which is why percentage heights need an explicit parent height.</p>