forked from Chalarangelo/30-seconds-of-css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2901 lines (2854 loc) · 135 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
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">
<title>30 Seconds of CSS</title>
<link rel="icon" type="image/png" sizes="32x32" href="./favicon-32x32.png">
<meta name="description" content="A curated collection of useful CSS snippets you can understand in 30 seconds or less. From foundational elements such as clearfix to gradient text color and gradient cursor tracking to CSS easing and far beyond.">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://30-seconds.github.io/30-seconds-of-css/">
<meta property="twitter:title" content="30 Seconds of CSS - Useful CSS snippets">
<meta property="twitter:description" content="A curated collection of useful CSS snippets you can understand in 30 seconds or less. ">
<meta property="twitter:image" content="./src/img/opengraph.png">
<meta property="og:type" content="website">
<meta property="og:url" content="https://30-seconds.github.io/30-seconds-of-css/">
<meta property="og:title" content="30 Seconds of CSS - Useful CSS snippets">
<meta property="og:description" content="A curated collection of useful CSS snippets you can understand in 30 seconds or less.">
<meta property="og:image" content="./src/img/opengraph.png">
<script src="./src/js/index.js" defer=""></script>
<script async="" defer="" src="https://buttons.github.io/buttons.js"></script>
</head>
<body>
<button class="back-to-top-button" aria-label="back to top"><i data-feather="arrow-up"></i></button>
<nav class="sidebar" aria-label="Table of Contents">
<button class="hamburger hamburger--spin sidebar__menu" type="button" aria-label="Menu" aria-expanded="false">
<span class="hamburger-box">
<span class="hamburger-inner"></span>
</span>
</button>
<div class="sidebar__links">
<section data-type="layout" class="sidebar__section">
<h4 class="sidebar__section-heading">layout</h4>
<a class="sidebar__link" href="#box-sizing-reset"><span>Box-sizing reset</span></a><a class="sidebar__link" href="#clearfix"><span>Clearfix</span></a><a class="sidebar__link" href="#constant-width-to-height-ratio"><span>Constant width to height ratio</span></a><a class="sidebar__link" href="#display-table-centering"><span>Display table centering</span></a><a class="sidebar__link" href="#evenly-distributed-children"><span>Evenly distributed children</span></a><a class="sidebar__link" href="#flexbox-centering"><span>Flexbox centering</span></a><a class="sidebar__link" href="#ghost-trick"><span>Ghost trick</span></a><a class="sidebar__link" href="#grid-centering"><span>Grid centering</span></a><a class="sidebar__link" href="#last-item-with-remaining-available-height"><span>Last item with remaining available height</span></a><a class="sidebar__link" href="#transform-centering"><span>Transform centering</span></a><a class="sidebar__link" href="#truncate-text-multiline"><span>Truncate text multiline</span></a><a class="sidebar__link" href="#truncate-text"><span>Truncate text</span></a>
</section>
<section data-type="visual" class="sidebar__section">
<h4 class="sidebar__section-heading">visual</h4>
<a class="sidebar__link" href="#circle"><span>Circle</span></a><a class="sidebar__link" href="#custom-scrollbar"><span>Custom scrollbar</span></a><a class="sidebar__link" href="#custom-text-selection"><span>Custom text selection</span></a><a class="sidebar__link" href="#dynamic-shadow"><span>Dynamic shadow</span></a><a class="sidebar__link" href="#etched-text"><span>Etched text</span></a><a class="sidebar__link" href="#fit-image-in-container"><span>Fit image in container</span></a><a class="sidebar__link" href="#fullscreen"><span>Fullscreen</span></a><a class="sidebar__link" href="#gradient-text"><span>Gradient text</span></a><a class="sidebar__link" href="#hairline-border"><span>Hairline border</span></a><a class="sidebar__link" href="#not-selector"><span>:not selector</span></a><a class="sidebar__link" href="#offscreen"><span>Offscreen</span></a><a class="sidebar__link" href="#overflow-scroll-gradient"><span>Overflow scroll gradient</span></a><a class="sidebar__link" href="#pretty-text-underline"><span>Pretty text underline</span></a><a class="sidebar__link" href="#reset-all-styles"><span>Reset all styles</span></a><a class="sidebar__link" href="#shape-separator"><span>Shape separator</span></a><a class="sidebar__link" href="#system-font-stack"><span>System font stack</span></a><a class="sidebar__link" href="#triangle"><span>Triangle</span></a><a class="sidebar__link" href="#zebra-striped-list"><span>Zebra striped list</span></a>
</section>
<section data-type="animation" class="sidebar__section">
<h4 class="sidebar__section-heading">animation</h4>
<a class="sidebar__link" href="#bouncing-loader"><span>Bouncing loader</span></a><a class="sidebar__link" href="#button-border-animation"><span>Button border animation</span></a><a class="sidebar__link" href="#donut-spinner"><span>Donut spinner</span></a><a class="sidebar__link" href="#easing-variables"><span>Easing variables</span></a><a class="sidebar__link" href="#height-transition"><span>Height transition</span></a><a class="sidebar__link" href="#hover-shadow-box-animation"><span>Hover shadow box animation</span></a><a class="sidebar__link" href="#hover-underline-animation"><span>Hover underline animation</span></a>
</section>
<section data-type="interactivity" class="sidebar__section">
<h4 class="sidebar__section-heading">interactivity</h4>
<a class="sidebar__link" href="#disable-selection"><span>Disable selection</span></a><a class="sidebar__link" href="#focus-within"><span>Focus Within</span></a><a class="sidebar__link" href="#mouse-cursor-gradient-tracking"><span>Mouse cursor gradient tracking</span></a><a class="sidebar__link" href="#popout-menu"><span>Popout menu</span></a><a class="sidebar__link" href="#sibling-fade"><span>Sibling fade</span></a><a class="sidebar__link" href="#toggle-switch"><span>Toggle switch</span></a>
</section>
<section data-type="other" class="sidebar__section">
<h4 class="sidebar__section-heading">other</h4>
<a class="sidebar__link" href="#calc"><span>Calc()</span></a><a class="sidebar__link" href="#counter"><span>Counter</span></a><a class="sidebar__link" href="#custom-variables"><span>Custom variables</span></a>
</section>
</div>
</nav>
<div class="content-wrapper">
<header class="header">
<div class="container">
<img class="header__leaves" draggable="false" id="header__leaves1" src="./src/img/leaves.svg" alt="">
<img class="header__leaves" draggable="false" id="header__leaves2" src="./src/img/leaves.svg" alt="">
<img id="header__blob" draggable="false" src="./src/img/blob.png" alt="">
<div class="header__content">
<img class="header__logo" draggable="false" src="./src/img/logo.png">
<h1 class="header__heading">30 Seconds of <strong class="header__css">CSS</strong></h1>
<p class="header__description">
A curated collection of useful CSS snippets you can understand in 30 seconds or less.
</p>
<div class="header__github-button-wrapper">
<a class="github-button header__github-button" href="https://github.com/30-seconds/30-seconds-of-css" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star 30-seconds/30-seconds-of-css on GitHub">Star</a>
</div>
</div>
</div>
</header>
<main class="main" id="main">
<div class="container">
<nav class="tags" aria-label="Filter by tags"><button class="tags__tag is-large is-active" data-type="all"><i data-feather="check"></i>all</button><button class="tags__tag is-large " data-type="layout"><i data-feather="layout"></i>layout</button><button class="tags__tag is-large " data-type="visual"><i data-feather="eye"></i>visual</button><button class="tags__tag is-large " data-type="animation"><i data-feather="loader"></i>animation</button><button class="tags__tag is-large " data-type="interactivity"><i data-feather="edit-2"></i>interactivity</button><button class="tags__tag is-large " data-type="other"><i data-feather="tag"></i>other</button></nav>
<div class="snippet">
<h3 id="bouncing-loader"><span>Bouncing loader</span><span class="tags__tag snippet__tag" data-type="animation"><i data-feather="loader"></i>animation</span></h3>
<p>Creates a bouncing loader animation.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">@keyframes bouncing-loader {
to {
opacity: 0.1;
transform: translate3d(0, -1rem, 0);
}
}
.bouncing-loader {
display: flex;
justify-content: center;
}
.bouncing-loader > div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}
.bouncing-loader > div:nth-child(2) {
animation-delay: 0.2s;
}
.bouncing-loader > div:nth-child(3) {
animation-delay: 0.4s;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="bouncing-loader.md">
<div class="bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
</div>
<style>@keyframes bouncing-loader {
to {
opacity: 0.1;
transform: translate3d(0, -1rem, 0); } }
[data-scope="bouncing-loader.md"] .bouncing-loader {
display: flex;
justify-content: center; }
[data-scope="bouncing-loader.md"] .bouncing-loader > div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate; }
[data-scope="bouncing-loader.md"] .bouncing-loader > div:nth-child(2) {
animation-delay: 0.2s; }
[data-scope="bouncing-loader.md"] .bouncing-loader > div:nth-child(3) {
animation-delay: 0.4s; }
</style>
<h4>Explanation</h4>
<p>Note: <code>1rem</code> is usually <code>16px</code>.</p>
<ol>
<li>
<p><code>@keyframes</code> defines an animation that has two states, where the element changes <code>opacity</code> and is translated up on the 2D plane using <code>transform: translate3d()</code>. Using a single axis translation on <code>transform: translate3d()</code> improves the performance of the animation.</p>
</li>
<li>
<p><code>.bouncing-loader</code> is the parent container of the bouncing circles and uses <code>display: flex</code>
and <code>justify-content: center</code> to position them in the center.</p>
</li>
<li>
<p><code>.bouncing-loader > div</code>, targets the three child <code>div</code>s of the parent to be styled. The <code>div</code>s are given a width and height of <code>1rem</code>, using <code>border-radius: 50%</code> to turn them from squares to circles.</p>
</li>
<li>
<p><code>margin: 3rem 0.2rem</code> specifies that each circle has a top/bottom margin of <code>3rem</code> and left/right margin
of <code>0.2rem</code> so that they do not directly touch each other, giving them some breathing room.</p>
</li>
<li>
<p><code>animation</code> is a shorthand property for the various animation properties: <code>animation-name</code>, <code>animation-duration</code>, <code>animation-iteration-count</code>, <code>animation-direction</code> are used.</p>
</li>
<li>
<p><code>nth-child(n)</code> targets the element which is the nth child of its parent.</p>
</li>
<li>
<p><code>animation-delay</code> is used on the second and third <code>div</code> respectively, so that each element does not start the animation at the same time.</p>
</li>
</ol>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
97.4%
</div>
</div>
<ul>
<li><a href="https://caniuse.com/#feat=css-animation" target="_blank">https://caniuse.com/#feat=css-animation</a></li>
</ul>
<!-- tags: animation -->
</div>
<div class="snippet">
<h3 id="box-sizing-reset"><span>Box-sizing reset</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3>
<p>Resets the box-model so that <code>width</code>s and <code>height</code>s are not affected by their <code>border</code>s or <code>padding</code>.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="box">border-box</div>
<div class="box content-box">content-box</div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
.box {
display: inline-block;
width: 150px;
height: 150px;
padding: 10px;
background: tomato;
color: white;
border: 10px solid red;
}
.content-box {
box-sizing: content-box;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="box-sizing-reset.md">
<div class="box">border-box</div>
<div class="box content-box">content-box</div>
</div>
<style>[data-scope="box-sizing-reset.md"] html {
box-sizing: border-box; }
[data-scope="box-sizing-reset.md"] *,
[data-scope="box-sizing-reset.md"] *::before,
[data-scope="box-sizing-reset.md"] *::after {
box-sizing: inherit; }
[data-scope="box-sizing-reset.md"] .box {
display: inline-block;
width: 150px;
height: 150px;
padding: 10px;
background: tomato;
color: white;
border: 10px solid red; }
[data-scope="box-sizing-reset.md"] .content-box {
box-sizing: content-box; }
</style>
<h4>Explanation</h4>
<ol>
<li><code>box-sizing: border-box</code> makes the addition of <code>padding</code> or <code>border</code>s not affect an element's <code>width</code> or <code>height</code>.</li>
<li><code>box-sizing: inherit</code> makes an element respect its parent's <code>box-sizing</code> rule.</li>
</ol>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
99.9%
</div>
</div>
<ul>
<li><a href="https://caniuse.com/#feat=css3-boxsizing" target="_blank">https://caniuse.com/#feat=css3-boxsizing</a></li>
</ul>
<!-- tags: layout -->
</div>
<div class="snippet">
<h3 id="button-border-animation"><span>Button border animation</span><span class="tags__tag snippet__tag" data-type="animation"><i data-feather="loader"></i>animation</span></h3>
<p>Creates a border animation on hover.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="button-border"><button class="button">Submit</button></div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.button {
background-color: #c47135;
border: none;
color: #ffffff;
outline: none;
padding: 12px 40px 10px;
position: relative;
}
.button:before,
.button:after {
border: 0 solid transparent;
transition: all 0.25s;
content: '';
height: 24px;
position: absolute;
width: 24px;
}
.button:before {
border-top: 2px solid #c47135;
left: 0px;
top: -5px;
}
.button:after {
border-bottom: 2px solid #c47135;
bottom: -5px;
right: 0px;
}
.button:hover {
background-color: #c47135;
}
.button:hover:before,
.button:hover:after {
height: 100%;
width: 100%;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="button-border-animation.md">
<div class="button-border"><button class="button">Submit</button></div>
</div>
<style>[data-scope="button-border-animation.md"] .button {
background-color: #c47135;
border: none;
color: #ffffff;
outline: none;
padding: 12px 40px 10px;
position: relative; }
[data-scope="button-border-animation.md"] .button:before,
[data-scope="button-border-animation.md"] .button:after {
border: 0 solid transparent;
transition: all 0.25s;
content: '';
height: 24px;
position: absolute;
width: 24px; }
[data-scope="button-border-animation.md"] .button:before {
border-top: 2px solid #c47135;
left: 0px;
top: -5px; }
[data-scope="button-border-animation.md"] .button:after {
border-bottom: 2px solid #c47135;
bottom: -5px;
right: 0px; }
[data-scope="button-border-animation.md"] .button:hover {
background-color: #c47135; }
[data-scope="button-border-animation.md"] .button:hover:before,
[data-scope="button-border-animation.md"] .button:hover:after {
height: 100%;
width: 100%; }
</style>
<h4>Explanation</h4>
<p>Use the <code>:before</code> and <code>:after</code> pseduo-elements as borders that animate on hover.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
100%
</div>
</div>
<!-- tags: animation -->
<!-- date: 2018-10-30 -->
</div>
<div class="snippet">
<h3 id="calc"><span>Calc()</span><span class="tags__tag snippet__tag" data-type="other"><i data-feather="tag"></i>other</span></h3>
<p>The function calc() allows to define CSS values with the use of mathematical expressions, the value adopted for the property is the result of a mathematical expression.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="box-example"></div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.box-example {
height: 280px;
background: #222 url('https://image.ibb.co/fUL9nS/wolf.png') no-repeat;
background-position: calc(100% - 20px) calc(100% - 20px);
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="calc.md">
<div class="box-example"></div>
</div>
<style>[data-scope="calc.md"] .box-example {
height: 280px;
background: #222 url("https://image.ibb.co/fUL9nS/wolf.png") no-repeat;
background-position: calc(100% - 20px) calc(100% - 20px); }
</style>
<p>If you want to align a background-image from right and bottom wasn't possible with just straight length values.
So now it's possible using calc():</p>
<div class="snippet-demo">
<div class="snippet-demo__calc">Background-image in the right/bottom</div>
</div>
<style>
.snippet-demo__calc {
height: 280px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
background: #222 url('https://image.ibb.co/fUL9nS/wolf.png') no-repeat;
background-position: calc(100% - 20px) calc(100% - 40px);
}
</style>
<h4>Explanation</h4>
<ol>
<li>It allows addition, subtraction, multiplication and division.</li>
<li>Can use different units (pixel and percent together, for example) for each value in your expression.</li>
<li>It is permitted to nest calc() functions.</li>
<li>It can be used in any property that <code><length></code>, <code><frequency></code>, <code><angle></code>, <code><time></code>, <code><number></code>, <code><color></code>, or <code><integer></code> is allowed, like width, height, font-size, top, left, etc.</li>
</ol>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
97.0%
</div>
</div>
<ul>
<li><a href="https://caniuse.com/#feat=calc" target="_blank">https://caniuse.com/#feat=calc</a></li>
</ul>
<!-- tags: other -->
</div>
<div class="snippet">
<h3 id="circle"><span>Circle</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3>
<p>Creates a circle shape with pure CSS.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="circle"></div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.circle {
border-radius: 50%;
width: 2rem;
height: 2rem;
background: #333;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="circle.md">
<div class="circle"></div>
</div>
<style>[data-scope="circle.md"] .circle {
border-radius: 50%;
width: 2rem;
height: 2rem;
background: #333; }
</style>
<h4>Explanation</h4>
<p><code>border-radius: 50%</code> curves the borders of an element to create a circle.</p>
<p>Since a circle has the same radius at any given point, the <code>width</code> and <code>height</code> must be the same. Differing
values will create an ellipse.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
97.7%
</div>
</div>
<ul>
<li><a href="https://caniuse.com/#feat=border-radius" target="_blank">https://caniuse.com/#feat=border-radius</a></li>
</ul>
<!-- tags: visual -->
</div>
<div class="snippet">
<h3 id="clearfix"><span>Clearfix</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3>
<p>Ensures that an element self-clears its children.</p>
<h6>Note: This is only useful if you are still using float to build layouts. Please consider using a modern approach with flexbox layout or grid layout.</h6>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="clearfix">
<div class="floated">float a</div>
<div class="floated">float b</div>
<div class="floated">float c</div>
</div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.clearfix::after {
content: '';
display: block;
clear: both;
}
.floated {
float: left;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="clearfix.md">
<div class="clearfix">
<div class="floated">float a</div>
<div class="floated">float b</div>
<div class="floated">float c</div>
</div>
</div>
<style>[data-scope="clearfix.md"] .clearfix::after {
content: '';
display: block;
clear: both; }
[data-scope="clearfix.md"] .floated {
float: left; }
</style>
<h4>Explanation</h4>
<ol>
<li><code>.clearfix::after</code> defines a pseudo-element.</li>
<li><code>content: ''</code> allows the pseudo-element to affect layout.</li>
<li><code>clear: both</code> indicates that the left, right or both sides of the element cannot be adjacent
to earlier floated elements within the same block formatting context.</li>
</ol>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
100%
</div>
</div>
<p><span class="snippet__support-note">⚠️ For this snippet to work properly you need to ensure that there are no non-floating children in the container and that there are no tall floats before the clearfixed container but in the same formatting context (e.g. floated columns).</span></p>
<!-- tags: layout -->
</div>
<div class="snippet">
<h3 id="constant-width-to-height-ratio"><span>Constant width to height ratio</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3>
<p>Given an element of variable width, it will ensure its height remains proportionate in a responsive fashion
(i.e., its width to height ratio remains constant).</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="constant-width-to-height-ratio"></div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.constant-width-to-height-ratio {
background: #333;
width: 50%;
}
.constant-width-to-height-ratio::before {
content: '';
padding-top: 100%;
float: left;
}
.constant-width-to-height-ratio::after {
content: '';
display: block;
clear: both;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="constant-width-to-height-ratio.md">
<div class="constant-width-to-height-ratio"></div>
</div>
<style>[data-scope="constant-width-to-height-ratio.md"] .constant-width-to-height-ratio {
background: #333;
width: 50%; }
[data-scope="constant-width-to-height-ratio.md"] .constant-width-to-height-ratio::before {
content: '';
padding-top: 100%;
float: left; }
[data-scope="constant-width-to-height-ratio.md"] .constant-width-to-height-ratio::after {
content: '';
display: block;
clear: both; }
</style>
<h4>Explanation</h4>
<p><code>padding-top</code> on the <code>::before</code> pseudo-element causes the height of the element to equal a percentage of
its width. <code>100%</code> therefore means the element's height will always be <code>100%</code> of the width, creating a responsive
square.</p>
<p>This method also allows content to be placed inside the element normally.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
100%
</div>
</div>
<!-- tags: layout -->
</div>
<div class="snippet">
<h3 id="counter"><span>Counter</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span><span class="tags__tag snippet__tag" data-type="other"><i data-feather="tag"></i>other</span></h3>
<p>Counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><ul>
<li>List item</li>
<li>List item</li>
<li>
List item
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
</li>
</ul>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">ul {
counter-reset: counter;
}
li::before {
counter-increment: counter;
content: counters(counter, '.') ' ';
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="counter.md">
<ul>
<li>List item</li>
<li>List item</li>
<li>
List item
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
</li>
</ul>
</div>
<style>[data-scope="counter.md"] ul {
counter-reset: counter; }
[data-scope="counter.md"] li::before {
counter-increment: counter;
content: counters(counter, ".") " "; }
</style>
<h4>Explanation</h4>
<p>You can create a ordered list using any type of HTML.</p>
<ol>
<li>
<p><code>counter-reset</code> Initializes a counter, the value is the name of the counter. By default, the counter starts at 0. This property can also be used to change its value to any specific number.</p>
</li>
<li>
<p><code>counter-increment</code> Used in element that will be countable. Once <code>counter-reset</code> initialized, a counter's value can be increased or decreased.</p>
</li>
<li>
<p><code>counter(name, style)</code> Displays the value of a section counter. Generally used in a <code>content</code> property. This function can receive two parameters, the first as the name of the counter and the second one can be <code>decimal</code> or <code>upper-roman</code> (<code>decimal</code> by default).</p>
</li>
<li>
<p><code>counters(counter, string, style)</code> Displays the value of a section counter. Generally used in a <code>content</code> property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be <code>decimal</code> or <code>upper-roman</code> (<code>decimal</code> by default).</p>
</li>
<li>
<p>A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the <code>counters()</code> function, separating text can be inserted between different levels of nested counters.</p>
</li>
</ol>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
99.9%
</div>
</div>
<ul>
<li><a href="https://caniuse.com/#feat=css-counters" target="_blank">https://caniuse.com/#feat=css-counters</a></li>
</ul>
<!-- tags: visual, other -->
</div>
<div class="snippet">
<h3 id="custom-scrollbar"><span>Custom scrollbar</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3>
<p>Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="custom-scrollbar">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.<br />
Iure id exercitationem nulla qui repellat laborum vitae, <br />
molestias tempora velit natus. Quas, assumenda nisi. <br />
Quisquam enim qui iure, consequatur velit sit?
</p>
</div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.custom-scrollbar {
height: 70px;
overflow-y: scroll;
}
/* To style the document scrollbar, remove `.custom-scrollbar` */
.custom-scrollbar::-webkit-scrollbar {
width: 8px;
}
.custom-scrollbar::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
border-radius: 10px;
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="custom-scrollbar.md">
<div class="custom-scrollbar">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit.<br>
Iure id exercitationem nulla qui repellat laborum vitae, <br>
molestias tempora velit natus. Quas, assumenda nisi. <br>
Quisquam enim qui iure, consequatur velit sit?
</p>
</div>
</div>
<style>[data-scope="custom-scrollbar.md"] {
/* To style the document scrollbar, remove `.custom-scrollbar` */ }
[data-scope="custom-scrollbar.md"] .custom-scrollbar {
height: 70px;
overflow-y: scroll; }
[data-scope="custom-scrollbar.md"] .custom-scrollbar::-webkit-scrollbar {
width: 8px; }
[data-scope="custom-scrollbar.md"] .custom-scrollbar::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px; }
[data-scope="custom-scrollbar.md"] .custom-scrollbar::-webkit-scrollbar-thumb {
border-radius: 10px;
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5); }
</style>
<h4>Explanation</h4>
<ol>
<li><code>::-webkit-scrollbar</code> targets the whole scrollbar element.</li>
<li><code>::-webkit-scrollbar-track</code> targets only the scrollbar track.</li>
<li><code>::-webkit-scrollbar-thumb</code> targets the scrollbar thumb.</li>
</ol>
<p>There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the <a href="https://webkit.org/blog/363/styling-scrollbars/" target="_blank">WebKit Blog</a>.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
90.7%
</div>
</div>
<p><span class="snippet__support-note">⚠️ Scrollbar styling doesn't appear to be on any standards track.</span></p>
<ul>
<li><a href="https://caniuse.com/#feat=css-scrollbar" target="_blank">https://caniuse.com/#feat=css-scrollbar</a></li>
</ul>
<!-- tags: visual -->
</div>
<div class="snippet">
<h3 id="custom-text-selection"><span>Custom text selection</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3>
<p>Changes the styling of text selection.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="custom-text-selection">Select some of this text.</p>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">::selection {
background: aquamarine;
color: black;
}
.custom-text-selection::selection {
background: deeppink;
color: white;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="custom-text-selection.md">
<p class="custom-text-selection">Select some of this text.</p>
</div>
<style>[data-scope="custom-text-selection.md"] ::selection {
background: aquamarine;
color: black; }
[data-scope="custom-text-selection.md"] .custom-text-selection::selection {
background: deeppink;
color: white; }
</style>
<h4>Explanation</h4>
<p><code>::selection</code> defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
86.5%
</div>
</div>
<p><span class="snippet__support-note">⚠️ Requires prefixes for full support and is not actually
in any specification.</span></p>
<ul>
<li><a href="https://caniuse.com/#feat=css-selection" target="_blank">https://caniuse.com/#feat=css-selection</a></li>
</ul>
<!-- tags: visual -->
</div>
<div class="snippet">
<h3 id="custom-variables"><span>Custom variables</span><span class="tags__tag snippet__tag" data-type="other"><i data-feather="tag"></i>other</span></h3>
<p>CSS variables that contain specific values to be reused throughout a document.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="custom-variables">CSS is awesome!</p>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">:root {
/* Place variables within here to use the variables globally. */
}
.custom-variables {
--some-color: #da7800;
--some-keyword: italic;
--some-size: 1.25em;
--some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;
color: var(--some-color);
font-size: var(--some-size);
font-style: var(--some-keyword);
text-shadow: var(--some-complex-value);
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="custom-variables.md">
<p class="custom-variables">CSS is awesome!</p>
</div>
<style>[data-scope="custom-variables.md"] :root {
/* Place variables within here to use the variables globally. */ }
[data-scope="custom-variables.md"] .custom-variables {
--some-color: #da7800;
--some-keyword: italic;
--some-size: 1.25em;
--some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;
color: var(--some-color);
font-size: var(--some-size);
font-style: var(--some-keyword);
text-shadow: var(--some-complex-value); }
</style>
<h4>Explanation</h4>
<p>The variables are defined globally within the <code>:root</code> CSS pseudo-class which matches the root element of a tree representing the document. Variables can also be scoped to a selector if defined within the block.</p>
<p>Declare a variable with <code>--variable-name:</code>.</p>
<p>Reuse variables throughout the document using the <code>var(--variable-name)</code> function.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
91.6%
</div>
</div>
<ul>
<li><a href="https://caniuse.com/#feat=css-variables" target="_blank">https://caniuse.com/#feat=css-variables</a></li>
</ul>
<!-- tags: other -->
</div>
<div class="snippet">
<h3 id="disable-selection"><span>Disable selection</span><span class="tags__tag snippet__tag" data-type="interactivity"><i data-feather="edit-2"></i>interactivity</span></h3>
<p>Makes the content unselectable.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p>You can select me.</p>
<p class="unselectable">You can't select me!</p>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.unselectable {
user-select: none;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="disable-selection.md">
<p>You can select me.</p>
<p class="unselectable">You can't select me!</p>
</div>
<style>[data-scope="disable-selection.md"] .unselectable {
user-select: none; }
</style>
<h4>Explanation</h4>
<p><code>user-select: none</code> specifies that the text cannot be selected.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
93.2%
</div>
</div>
<p><span class="snippet__support-note">⚠️ Requires prefixes for full support.</span>
<br>
<span class="snippet__support-note">⚠️ This is not a secure method to prevent users from copying content.</span></p>
<ul>
<li><a href="https://caniuse.com/#feat=user-select-none" target="_blank">https://caniuse.com/#feat=user-select-none</a></li>
</ul>
<!-- tags: interactivity -->
</div>
<div class="snippet">
<h3 id="display-table-centering"><span>Display table centering</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3>
<p>Vertically and horizontally centers a child element within its parent element using <code>display: table</code> (as an alternative to <code>flexbox</code>).</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="container">
<div class="center"><span>Centered content</span></div>
</div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.container {
border: 1px solid #333;
height: 250px;
width: 250px;
}
.center {
display: table;
height: 100%;
width: 100%;
}
.center > span {
display: table-cell;
text-align: center;
vertical-align: middle;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="display-table-centering.md">
<div class="container">
<div class="center"><span>Centered content</span></div>
</div>
</div>
<style>[data-scope="display-table-centering.md"] .container {
border: 1px solid #333;
height: 250px;
width: 250px; }
[data-scope="display-table-centering.md"] .center {
display: table;
height: 100%;
width: 100%; }
[data-scope="display-table-centering.md"] .center > span {
display: table-cell;
text-align: center;
vertical-align: middle; }
</style>
<h4>Explanation</h4>
<ol>
<li><code>display: table</code> on '.center' allows the element to behave like a <code><table></code> HTML element.</li>
<li>100% height and width on '.center' allows the element to fill the available space within its parent element.</li>
<li><code>display: table-cell</code> on '.center > span' allows the element to behave like an HTML element.</li>
<li><code>text-align: center</code> on '.center > span' centers the child element horizontally.</li>
<li><code>vertical-align: middle</code> on '.center > span' centers the child element vertically.</li>
</ol>
<p>The outer parent ('.container' in this case) must have a fixed height and width.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
100%
</div>
</div>
<ul>
<li><a href="https://caniuse.com/#search=display%3A%20table" target="_blank">https://caniuse.com/#search=display%3A%20table</a></li>
</ul>
<!-- tags: layout -->
</div>
<div class="snippet">
<h3 id="donut-spinner"><span>Donut spinner</span><span class="tags__tag snippet__tag" data-type="animation"><i data-feather="loader"></i>animation</span></h3>
<p>Creates a donut spinner that can be used to indicate the loading of content.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="donut"></div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">@keyframes donut-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.donut {
display: inline-block;
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #7983ff;
border-radius: 50%;
width: 30px;
height: 30px;
animation: donut-spin 1.2s linear infinite;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="donut-spinner.md">
<div class="donut"></div>
</div>
<style>@keyframes donut-spin {
0% {
transform: rotate(0deg); }
100% {
transform: rotate(360deg); } }
[data-scope="donut-spinner.md"] .donut {
display: inline-block;
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #7983ff;
border-radius: 50%;
width: 30px;
height: 30px;
animation: donut-spin 1.2s linear infinite; }
</style>
<h4>Explanation</h4>
<p>Use a semi-transparent <code>border</code> for the whole element, except one side that will
serve as the loading indicator for the donut. Use <code>animation</code> to rotate the element.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
97.4%
</div>
</div>
<p><span class="snippet__support-note">⚠️ Requires prefixes for full support.</span></p>
<ul>
<li><a href="https://caniuse.com/#feat=css-animation" target="_blank">https://caniuse.com/#feat=css-animation</a></li>
<li><a href="https://caniuse.com/#feat=transforms2d" target="_blank">https://caniuse.com/#feat=transforms2d</a></li>
</ul>
<!-- tags: animation -->
</div>
<div class="snippet">
<h3 id="dynamic-shadow"><span>Dynamic shadow</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3>
<p>Creates a shadow similar to <code>box-shadow</code> but based on the colors of the element itself.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="dynamic-shadow"></div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.dynamic-shadow {
position: relative;
width: 10rem;
height: 10rem;
background: linear-gradient(75deg, #6d78ff, #00ffb8);
z-index: 1;
}
.dynamic-shadow::after {
content: '';
width: 100%;
height: 100%;
position: absolute;
background: inherit;
top: 0.5rem;
filter: blur(0.4rem);
opacity: 0.7;
z-index: -1;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo" data-scope="dynamic-shadow.md">
<div class="dynamic-shadow"></div>
</div>
<style>[data-scope="dynamic-shadow.md"] .dynamic-shadow {
position: relative;
width: 10rem;
height: 10rem;
background: linear-gradient(75deg, #6d78ff, #00ffb8);
z-index: 1; }
[data-scope="dynamic-shadow.md"] .dynamic-shadow::after {
content: '';
width: 100%;
height: 100%;
position: absolute;
background: inherit;
top: 0.5rem;
filter: blur(0.4rem);
opacity: 0.7;
z-index: -1; }
</style>
<h4>Explanation</h4>
<ol>
<li><code>position: relative</code> on the element establishes a Cartesian positioning context for psuedo-elements.</li>
<li><code>z-index: 1</code> establishes a new stacking context.</li>
<li><code>::after</code> defines a pseudo-element.</li>
<li><code>position: absolute</code> takes the pseudo element out of the flow of the document and positions it in relation to the parent.</li>
<li><code>width: 100%</code> and <code>height: 100%</code> sizes the pseudo-element to fill its parent's dimensions, making it equal in size.</li>
<li><code>background: inherit</code> causes the pseudo-element to inherit the linear gradient specified on the element.</li>
<li><code>top: 0.5rem</code> offsets the pseudo-element down slightly from its parent.</li>
<li><code>filter: blur(0.4rem)</code> will blur the pseudo-element to create the appearance of a shadow underneath.</li>
<li><code>opacity: 0.7</code> makes the pseudo-element partially transparent.</li>
<li><code>z-index: -1</code> positions the pseudo-element behind the parent but in front of the background.</li>
</ol>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
94.2%
</div>
</div>
<p><span class="snippet__support-note">⚠️ Requires prefixes for full support.</span></p>
<ul>
<li><a href="https://caniuse.com/#feat=css-filters" target="_blank">https://caniuse.com/#feat=css-filters</a></li>
</ul>
<!-- tags: visual -->
</div>
<div class="snippet">
<h3 id="easing-variables"><span>Easing variables</span><span class="tags__tag snippet__tag" data-type="animation"><i data-feather="loader"></i>animation</span></h3>
<p>Variables that can be reused for <code>transition-timing-function</code> properties, more
powerful than the built-in <code>ease</code>, <code>ease-in</code>, <code>ease-out</code> and <code>ease-in-out</code>.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="easing-variables">Hover</div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">:root {
/* Place variables in here to use globally */
}
.easing-variables {
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);