forked from Chalarangelo/30-seconds-of-css
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
2307 lines (2274 loc) · 104 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>
<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.">
<link rel="icon" type="image/png" sizes="32x32" href="./favicon-32x32.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="#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="#grid-centering"><span>Grid centering</span></a>
<a class="sidebar__link" href="#grid-layout"><span>Grid layout</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="#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="#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>
</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="#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-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="#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>
</section>
<section data-type="other" class="sidebar__section">
<h4 class="sidebar__section-heading">other</h4>
<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__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/atomiks/30-seconds-of-css" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star atomiks/30-seconds-of-css on GitHub">Star</a>
</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 {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0.1;
transform: translateY(-1rem);
}
}
.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">
<div class="snippet-demo__bouncing-loader">
<div></div>
<div></div>
<div></div>
</div>
</div>
<style>
@keyframes bouncing-loader {
from {
opacity: 1;
transform: translateY(0);
}
to {
opacity: 0.1;
transform: translateY(-1rem);
}
}
.snippet-demo__bouncing-loader {
display: flex;
justify-content: center;
}
.snippet-demo__bouncing-loader>div {
width: 1rem;
height: 1rem;
margin: 3rem 0.2rem;
background: #8385aa;
border-radius: 50%;
animation: bouncing-loader 0.6s infinite alternate;
}
.snippet-demo__bouncing-loader>div:nth-child(2) {
animation-delay: 0.2s;
}
.snippet-demo__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: translateY()</code>.</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">
95.3%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<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="CSS">CSS</h4><pre><code class="lang-css">html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo">
<div class="snippet-demo__box-sizing-reset">Demo</div>
</div>
<style>
.snippet-demo__box-sizing-reset {
box-sizing: border-box;
width: 200px;
padding: 1.5em;
color: #7983ff;
font-family: sans-serif;
background-color: white;
border: 5px solid;
}
</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">
98.4%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<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="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">
<div class="snippet-demo__circle"></div>
</div>
<style>
.snippet-demo__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">
95.5%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<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">
<div class="snippet-demo__clearfix">
<div class="snippet-demo__floated">float a</div>
<div class="snippet-demo__floated">float b</div>
<div class="snippet-demo__floated">float c</div>
</div>
</div>
<style>
.snippet-demo__clearfix::after {
content: '';
display: block;
clear: both;
}
.snippet-demo__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">
99+%
</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>
<p>Resize your browser window to see the proportion of the element remain the same.</p>
<div class="snippet-demo">
<div class="snippet-demo__constant-width-to-height-ratio"></div>
</div>
<style>
.snippet-demo__constant-width-to-height-ratio {
background: #333;
width: 50%;
}
.snippet-demo__constant-width-to-height-ratio::before {
content: '';
padding-top: 100%;
float: left;
}
.snippet-demo__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">
99+%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<!-- 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</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">
<div class="snippet-demo__countable-section">
<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>
</div>
<style>
.snippet-demo__countable-section ul {
counter-reset: counter;
list-style-type: none;
}
.snippet-demo__countable-section 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 in 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 recieve 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 recieve 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">
98.4%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<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. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?</p>
</div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">/* Document scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}
/* Scrollable element */
.some-element::webkit-scrollbar {
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo">
<div class="snippet-demo__custom-scrollbar">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?
</p>
</div>
</div>
<style>
.snippet-demo__custom-scrollbar {
height: 100px;
overflow: auto;
}
.snippet-demo__custom-scrollbar::-webkit-scrollbar {
width: 8px;
}
.snippet-demo__custom-scrollbar::-webkit-scrollbar-track {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
.snippet-demo__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">
88.0%
</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">
<p class="snippet-demo__custom-text-selection">Select some of this text.</p>
</div>
<style>
.snippet-demo__custom-text-selection::selection {
background: deeppink;
color: white;
}
.snippet-demo__custom-text-selection::-moz-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">
84.9%
</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 {
--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;
}
.custom-variables {
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">
<div class="snippet-demo__custom-variables">
<p>CSS is awesome!</p>
</div>
</div>
<style>
.snippet-demo__custom-variables {
--some-color: #686868;
--some-keyword: italic;
--some-size: 1.25em;
--some-complex-value: 1px 1px 2px whitesmoke, 0 0 1em slategray, 0 0 0.2em slategray;
}
.snippet-demo__custom-variables p {
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">
88.0%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<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">
<p>You can select me.</p>
<p class="snippet-demo__disable-selection">You can't select me!</p>
</div>
<style>
.snippet-demo__disable-selection {
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">
87.2%
</div>
</div>
<p><span class="snippet__support-note">⚠️ Requires prefixes for full support.</span>
<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="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">
<div class="snippet-demo__donut-spinner"></div>
</div>
<style>
@keyframes snippet-demo__donut-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.snippet-demo__donut-spinner {
display: inline-block;
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #7983ff;
border-radius: 50%;
width: 30px;
height: 30px;
animation: snippet-demo__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">
95.3%
</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">
<div class="snippet-demo__dynamic-shadow"></div>
</div>
<style>
.snippet-demo__dynamic-shadow {
position: relative;
width: 10rem;
height: 10rem;
background: linear-gradient(75deg, #6d78ff, #00ffb8);
z-index: 1;
}
.snippet-demo__dynamic-shadow::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
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">
91.7%
</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"></div>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">:root {
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
--ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
--ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
--ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
--ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
--ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
--ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
--ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
--ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
--ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
--ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1);
--ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);
--ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1);
--ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);
--ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
--ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
--ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
}
.easing-variables {
width: 50px;
height: 50px;
background: #333;
transition: transform 1s var(--ease-out-quart);
}
.easing-variables:hover {
transform: rotate(45deg);
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo">
<div class="snippet-demo__easing-variables">Hover</div>
</div>
<style>
:root {
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
--ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
--ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
--ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
--ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
--ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
--ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
--ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
--ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
--ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
--ease-out-circ: cubic-bezier(0.075, 0.82, 0.165, 1);
--ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);
--ease-in-out-cubic: cubic-bezier(0.645, 0.045, 0.355, 1);
--ease-in-out-quart: cubic-bezier(0.77, 0, 0.175, 1);
--ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
--ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
--ease-in-out-circ: cubic-bezier(0.785, 0.135, 0.15, 0.86);
}
.snippet-demo__easing-variables {
width: 75px;
height: 75px;
background: #333;
color: white;
font-size: 0.8rem;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
transition: transform 1s var(--ease-out-quart);
}
.snippet-demo__easing-variables:hover {
transform: rotate(45deg);
}
</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. In HTML, <code>:root</code> represents the <code><html></code> element and is identical
to the selector <code>html</code>, except that its specificity is higher.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
88.0%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<ul>
<li>
<a href="https://caniuse.com/#feat=css-variables" target="_blank">https://caniuse.com/#feat=css-variables</a>
</li>
</ul>
<!-- tags: animation -->
</div>
<div class="snippet">
<h3 id="etched-text"><span>Etched text</span><span class="tags__tag snippet__tag" data-type="visual"><i data-feather="eye"></i>visual</span></h3>
<p>Creates an effect where text appears to be "etched" or engraved into the background.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><p class="etched-text">I appear etched into the background.</p>
</code></pre>
<h4 data-type="CSS">CSS</h4><pre><code class="lang-css">.etched-text {
text-shadow: 0 2px white;
font-size: 1.5rem;
font-weight: bold;
color: #b8bec5;
}
</code></pre>
<h4>Demo</h4>
<div class="snippet-demo">
<p class="snippet-demo__etched-text">I appear etched into the background.</p>
</div>
<style>
.snippet-demo__etched-text {
font-size: 1.5rem;
font-weight: bold;
color: #b8bec5;
text-shadow: 0 2px 0 white;
}
</style>
<h4>Explanation</h4>
<p><code>text-shadow: 0 2px white</code> creates a white shadow offset <code>0px</code> horizontally and <code>2px</code> vertically from the origin position.</p>
<p>The background must be darker than the shadow for the effect to work.</p>
<p>The text color should be slightly faded to make it look like it's engraved/carved out of the background.</p>
<h4>Browser support</h4>
<div>
<div class="snippet__browser-support">
98.1%
</div>
</div>
<p><span class="snippet__support-note">✅ No caveats.</span></p>
<ul>
<li>
<a href="https://caniuse.com/#feat=css-textshadow" target="_blank">https://caniuse.com/#feat=css-textshadow</a>
</li>
</ul>
<!-- tags: visual -->
</div>
<div class="snippet">
<h3 id="evenly-distributed-children"><span>Evenly distributed children</span><span class="tags__tag snippet__tag" data-type="layout"><i data-feather="layout"></i>layout</span></h3>
<p>Evenly distributes child elements within a parent element.</p>
<h4 data-type="HTML">HTML</h4><pre><code class="lang-html"><div class="evenly-distributed-children">
<p>Item1</p>
<p>Item2</p>
<p>Item3</p>
</div>
</code></pre>