-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathslider-styler.html
981 lines (904 loc) · 39.1 KB
/
slider-styler.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<!-- Primary Meta Tags -->
<title>Input range slider CSS styler across browsers</title>
<meta name="title" content="Input range slider CSS styler across browsers">
<meta name="description" content="Style <input> range sliders across browsers! Easy!">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://toughengineer.github.io/demo/slider-styler">
<meta property="og:title" content="Input range slider CSS styler across browsers">
<meta property="og:description" content="Style <input> range sliders across browsers! Easy!">
<meta property="og:image" content="https://toughengineer.github.io/demo/slider-styler/thumbnail.png">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://toughengineer.github.io/demo/slider-styler">
<meta property="twitter:title" content="Input range slider CSS styler across browsers">
<meta property="twitter:description" content="Style <input> range sliders across browsers! Easy!">
<meta property="twitter:image" content="https://toughengineer.github.io/demo/slider-styler/thumbnail.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/themes/monolith.min.css" />
<style type="text/css">
.notQuite100PercentWide {
max-width: 70em;
}
h1, h3 {
text-align: center;
margin-top: 0.5em;
margin-bottom: 1em;
}
.textblock {
margin: 1em;
}
p {
font-size: 1.1em;
line-height: 150%;
}
.note {
color: #222;
font-size: 0.9em;
}
.notePanel {
display: inline-block;
background: #fdfdfd;
border-radius: 0.5em;
padding: 0 1em 0 1em;
box-shadow: 0 0 0.5em #eee;
}
a[target="_blank"]:not(.no-external-link-icon) {
white-space: nowrap;
}
a[target="_blank"]:not(.no-external-link-icon)::after {
content: "";
width: 1em;
height: 1em;
background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiI+PHBhdGggZD0iTTkgMnYxaDMuM0w2IDkuM2wuNy43TDEzIDMuN1Y3aDFWMnpNNCA0YTIgMiAwIDAwLTIgMnY2YzAgMS4xLjkgMiAyIDJoNmEyIDIgMCAwMDItMlY3bC0xIDF2NGMwIC42LS40IDEtMSAxSDRhMSAxIDAgMDEtMS0xVjZjMC0uNi40LTEgMS0xaDRsMS0xeiIvPjwvc3ZnPg==) no-repeat;
background-size: contain;
margin: 0 0.05em 0 0.1em;
display: inline-block;
vertical-align: middle;
}
img.icon {
width: 1em;
height: 1em;
vertical-align: middle;
}
.dummy {
visibility: hidden;
pointer-events: none;
}
.example {
border: 0.5em solid #f5f5f5;
vertical-align: middle;
}
.group {
margin: 1em;
padding: 1em;
border: 1px solid #ccc;
border-radius: 0.7em;
box-shadow: 0 0 0.5em #eee;
}
.subgroup {
margin: 0.5em 0 0.5em 0;
}
.subgroup:last-child {
margin-bottom: 0;
}
.subgroup + .subgroup {
margin-top: 1.5em;
}
.subgroupBorder {
padding: 0.5em;
border: 1px solid #ddd;
border-radius: 0.35em;
box-shadow: 0 0 0.25em #eee;
}
.subgroupBorder + .subgroupBorder {
margin-top: 1em;
}
input[type="number"] {
width: 5em;
}
input[type="checkbox"] {
vertical-align: middle;
}
.raw, .raw input {
font-family: Courier, monospace;
font-size: 1em;
}
.validationDisplay {
padding: 3px;
border: 3px solid transparent;
border-radius: 5px;
}
.validationDisplay.invalid {
border-color: #f55;
}
.flexVCentered {
display: flex;
align-items: center;
}
.grow1 {
flex-grow: 1;
}
.code {
font-family: Courier, monospace;
}
.colorPicker {
display: inline-block;
vertical-align: middle;
margin: 0 0.5em 0 0.5em;
}
.colorPicker button {
box-shadow: 0 0 1px 1px #ddd;
}
.colorPickerContainer {
display: inline-block;
vertical-align: middle;
}
input.visibilityControl:not(:checked) ~ .hidden {
display: none;
}
input.visibilityControl:not(:checked) ~ .invisible {
visibility: hidden;
}
.stickyCssBlock {
position: sticky;
top: 20vh;
}
.fadedButton {
background-color: #efefef;
margin-left: 0.3em;
margin-right: 0.3em;
border: 1px solid black;
border-radius: 0.3em;
transition: background-color 0.5s;
opacity: 0.5;
}
.fadedButton:hover {
opacity: 1;
}
.fadedButton.copied {
background-color: #0c0;
transition: background-color 0s;
}
.fadedButton.not-copied {
background-color: #e55;
transition: background-color 0s;
}
.copyIcon::before {
content: "";
width: 1em;
height: 1em;
background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0iYmxhY2siIHdpZHRoPSIxOHB4IiBoZWlnaHQ9IjE4cHgiPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMHoiIGZpbGw9Im5vbmUiLz48cGF0aCBkPSJNMTYgMUg0Yy0xLjEgMC0yIC45LTIgMnYxNGgyVjNoMTJWMXptMyA0SDhjLTEuMSAwLTIgLjktMiAydjE0YzAgMS4xLjkgMiAyIDJoMTFjMS4xIDAgMi0uOSAyLTJWN2MwLTEuMS0uOS0yLTItMnptMCAxNkg4VjdoMTF2MTR6Ii8+PC9zdmc+) no-repeat;
background-size: contain;
margin-right: 0.1em;
display: inline-block;
vertical-align: text-bottom;
}
.resetIcon::before {
content: "\21BA";
margin-right: 0.3em;
}
input:not(:checked) ~ .pinIcon {
opacity: 0.5;
}
textarea {
font-size: 1em;
resize: none;
}
.codeContainer {
display: block;
border: 1px solid #ccc;
padding: 0.5em;
margin: 0.25em 0 0.25em 0;
box-shadow: 0 0 0.5em #eee;
overflow: auto;
font-family: Courier, monospace;
white-space: pre;
}
.credits:not(:hover) {
opacity: 0.33;
}
</style>
<style id="styleElement" type="text/css"></style>
</head>
<body>
<div class="textblock notQuite100PercentWide">
<h1>Input range slider CSS styler across browsers</h1>
<p>
Style <code><input></code> range sliders CSS across browsers!<br />
Use convenient controls, or edit CSS properties directly.
<span class="note">
CSS property inputs indicate when the value is
<span class="raw validationDisplay invalid" style="display: inline-block;"><input value="invalid" readonly /></span>
</span><br />
You'll figure it out, I believe in you!
</p>
<p>
This styler is <em>kinda</em> tested in Chrome and Firefox (end of 2020), and Safari 13 (OS X 10.15).
It even kinda works in the old Edge <span class="note">(not the Chromium based)</span>.<br />
It does not work in IE though.
</p>
<div class="notePanel">
<p>
Read <a href="https://css-tricks.com/sliding-nightmare-understanding-range-input/"
title="A Sliding Nightmare: Understanding the Range Input"
target="_blank"
rel="noopener"><em>this great article</em></a>
if you want to know how <code><input></code> range CSS styling works under the hood.<br />
It's a shame that in 2020 styling of sliders is not yet standardized.
Here is
<a href="https://github.com/w3c/csswg-drafts/issues/4410"
title="[css-pseudo-4] Standardizing input[type="range"] styling"
target="_blank"
rel="noopener">a proposal</a> for standardization that I know of.
</p>
</div>
<p>
Go to the explanation <a href="#explanation">below</a> for more details.
</p>
<p>
Examples: <span class="note">(gray border indicates edges of <code><input></code> elements)</span>
</p>
</div>
<div class="notQuite100PercentWide">
<div>
Without styling:<br />
<div class="example" style="display: inline-block;">
<input type="range" />
</div>
<div class="example">
<input type="range" style="width:100%;" />
</div>
</div>
</div>
<div id="controlsContainer" style="display: grid;">
<!--this dummy defines the height of the grid item-->
<div class="dummy" style="grid-area: 1/1;">
<br />
<div class="example">
<input class="styled-slider" type="range" />
</div>
<div class="example">
<input class="styled-slider" type="range" />
</div>
<div class="progressSubContainer">
<br />
<div class="example">
<input class="styled-slider slider-progress" type="range" />
</div>
<div class="example">
<input class="styled-slider slider-progress" type="range" />
</div>
</div>
<div style="height: 1em;"></div>
</div>
<div id="examples" style="grid-area: 1/1; align-self: end; max-height: 20vh; position: sticky; top: 0; z-index: 9000; pointer-events: none;">
<!--this dummy defines the height of the *desired* height of the item-->
<div class="dummy">
<br />
<div class="example">
<input class="styled-slider" type="range" />
</div>
<div class="example">
<input class="styled-slider" type="range" />
</div>
<div class="progressSubContainer">
<br />
<div class="example">
<input class="styled-slider slider-progress" type="range" />
</div>
<div class="example">
<input class="styled-slider slider-progress" type="range" />
</div>
</div>
<div style="height: 1em;"></div>
</div>
<div style="position: absolute; bottom: 0; width: 100%">
<div style="background: white; position: initial; pointer-events: auto;">
<div class="notQuite100PercentWide">
<div>
Styled sliders:<br />
<div class="example" style="display: inline-block;">
<input class="styled-slider" type="range" />
</div>
<span class="note" style="margin-left: 1em;">use</span>
<span id="styledSliderClass" class="code">class="styled-slider"</span>
<button id="copyStyledSliderButtonClass" class="fadedButton" title="Copy class attribute."><span class="copyIcon">copy</span></button>
<div class="example">
<input class="styled-slider" type="range" style="width:100%;" />
</div>
</div>
<div class="progressSubContainer">
Styled sliders with progress:<br />
<div class="example" style="display: inline-block;">
<input class="styled-slider slider-progress" type="range" />
</div>
<span class="note" style="margin-left: 1em;">use</span>
<span id="styledSliderProgressClass" class="code">class="styled-slider slider-progress"</span>
<button id="copyStyledSliderProgressButtonClass" class="fadedButton" title="Copy class attribute."><span class="copyIcon">copy</span></button>
<div class="example">
<input class="styled-slider slider-progress" type="range" style="width:100%;" />
</div>
</div>
</div>
</div>
<div style="height: 1em; background: linear-gradient(white, #fff0);"></div>
</div>
</div>
<div style="grid-area: 2/1;">
<div style="display: inline-block; width: 100%; min-width: 30em; max-width: 40em; ">
<!--element height section-->
<div id="element" class="group">
<h3><code><input></code> element itself</h3>
<!--height section-->
<div id="height" class="subgroup">
<label>
<strong>Height:</strong>
<input id="height" type="number" value="0" min="0" />
</label>
<select id="heightUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
height:
<input id="rawHeight" type="text" placeholder="not defined" class="grow1" />
</label>
</div>
<span class="note">
Set to desired height, e.g. slightly larger than the largest height of handle and track.<br />
Otherwise set to zero or empty value to keep the default height defined by browser.
</span>
</div>
<!--outline section-->
<div id="outline" class="subgroup">
<label>
<input id="disableOutline" type="checkbox" min="0" />
<strong>disable focus outline</strong>
</label>
<div class="note subgroup">
Focus outline for customized slider appearance generally looks ugly.<br />
One way to make it work is to set <code><input></code> element height (above) greater than
the height of the handle.
</div>
</div>
</div>
<!--handle section-->
<div id="handle" class="group">
<h3>
<label title="Hiding handle is not supported for old non-Chromium-based Edge.">
<input id="isPresent" type="checkbox" checked />
<strong>handle (thumb)</strong><span style="color: lightgray;"> *</span>
</label>
</h3>
<!-- background section -->
<div id="background" class="subgroup">
<!-- normal section -->
<div id="normal" class="subgroup">
<label><strong>Background:</strong></label>
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :hover section -->
<div id="hover" class="subgroupBorder">
<input id="handleBackgroundHoverCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="handleBackgroundHoverCheckbox">:hover</label>
<div class="colorPickerContainer invisible">
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
</div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered grow1">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :active section -->
<div id="active" class="subgroupBorder">
<input id="handleBackgroundActiveCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="handleBackgroundActiveCheckbox">:active</label>
<div class="colorPickerContainer invisible">
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
</div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
<div class="validationDisplay"></div>
</div>
</div>
</div>
<!-- width section -->
<div id="width" class="subgroup">
<label>
<strong>Width:</strong>
<input id="width" type="number" value="0" min="0" />
</label>
<select id="widthUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
width:
<input id="rawWidth" type="text" class="grow1" />
</label>
</div>
</div>
<!-- height section -->
<div id="height" class="subgroup">
<label>
<strong>Height:</strong>
<input id="height" type="number" value="0" min="0" />
</label>
<select id="heightUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
height:
<input id="rawHeight" type="text" class="grow1" />
</label>
</div>
</div>
<!-- border radius section -->
<div id="borderRadius" class="subgroup">
<label>
<strong>Border radius:</strong>
<input id="borderRadius" type="number" value="0" min="0" />
</label>
<select id="borderRadiusUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
border-radius:
<input id="rawBorderRadius" type="text" class="grow1" />
</label>
</div>
</div>
<!-- border section -->
<div id="border" class="subgroup">
<!-- normal section -->
<div id="normal" class="subgroup">
<label>
<strong>Border:</strong>
<input id="borderWidth" type="number" value="0" min="0" />
</label>
<select id="borderWidthUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="colorPicker"><div id="borderColor"></div></div>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
border:
<input id="rawBorder" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :hover section -->
<div id="hover" class="subgroupBorder">
<input id="handleBorderColorHoverCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="handleBorderColorHoverCheckbox">:hover</label>
<div class="colorPickerContainer invisible"><div id="borderColor"></div></div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
border-color:
<input id="rawBorderColor" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :active section -->
<div id="active" class="subgroupBorder">
<input id="handleBorderColorActiveCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="handleBorderColorActiveCheckbox">:active</label>
<div class="colorPickerContainer invisible"><div id="borderColor"></div></div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
border-color:
<input id="rawBorderColor" type="text" class="grow1" />
</label>
</div>
</div>
</div>
<!-- shadow section -->
<div id="shadow" class="subgroup">
<div>
<label><strong>Shadow:</strong></label>
<div class="colorPicker"><div id="shadowColor"></div></div>
</div>
<div style="display: inline-block; margin-top: 0.5em; text-align: right;">
<div>
<label>x offset <input id="shadowX" type="number" value="0" /></label>
<select id="shadowXUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
<div>
<label>y offset <input id="shadowY" type="number" value="0" /></label>
<select id="shadowYUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
<div>
<label>blur <input id="shadowBlur" type="number" value="0" min="0" /></label>
<select id="shadowBlurUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
<div>
<label>spread <input id="shadowSpread" type="number" value="0" min="0" /></label>
<select id="shadowSpreadUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
</div>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
box-shadow:
<input id="rawShadow" type="text" class="grow1" />
</label>
</div>
</div>
</div>
<!-- track section -->
<div id="track" class="group">
<h3>
<label title="Hiding track is not supported for old non-Chromium-based Edge.">
<input id="isPresent" type="checkbox" checked />
<strong>track</strong><span style="color: lightgray;"> *</span>
</label>
</h3>
<!-- background section -->
<div id="background" class="subgroup">
<!-- normal section -->
<div id="normal" class="subgroup">
<label><strong>Background:</strong></label>
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :hover section -->
<div id="hover" class="subgroupBorder">
<input id="trackBackgroundHoverCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="trackBackgroundHoverCheckbox">:hover</label>
<div class="colorPickerContainer invisible">
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
</div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :active section -->
<div id="active" class="subgroupBorder">
<input id="trackBackgroundActiveCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="trackBackgroundActiveCheckbox">:active</label>
<div class="colorPickerContainer invisible">
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
</div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
</div>
<!-- height section -->
<div id="height" class="subgroup">
<label>
<strong>Height:</strong>
<input id="height" type="number" value="0" min="0" />
</label>
<select id="heightUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
height:
<input id="rawHeight" type="text" class="grow1" />
</label>
</div>
</div>
<!-- width section -->
<div id="borderRadius" class="subgroup">
<label>
<strong>Border radius:</strong>
<input id="borderRadius" type="number" value="0" min="0" />
</label>
<select id="borderRadiusUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
border-radius:
<input id="rawBorderRadius" type="text" class="grow1" />
</label>
</div>
</div>
<!-- border section -->
<div id="border" class="subgroup">
<!-- normal section -->
<div id="normal" class="subgroup">
<label>
<strong>Border:</strong>
<input id="borderWidth" type="number" value="0" min="0" />
</label>
<select id="borderWidthUnit">
<option selected>px</option>
<option>em</option>
</select>
<div class="colorPicker"><div id="borderColor"></div></div>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
border:
<input id="rawBorder" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :hover section -->
<div id="hover" class="subgroupBorder">
<input id="trackBorderColorHoverCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="trackBorderColorHoverCheckbox">:hover</label>
<div class="colorPickerContainer invisible"><div id="borderColor"></div></div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
border-color:
<input id="rawBorderColor" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :active section -->
<div id="active" class="subgroupBorder">
<input id="trackBorderColorActiveCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="trackBorderColorActiveCheckbox">:active</label>
<div class="colorPickerContainer invisible"><div id="borderColor"></div></div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
border-color:
<input id="rawBorderColor" type="text" class="grow1" />
</label>
</div>
</div>
</div>
<!-- shadow section -->
<div id="shadow" class="subgroup">
<div>
<label><strong>Shadow:</strong></label>
<div class="colorPicker"><div id="shadowColor"></div></div>
</div>
<div style="display: inline-block; margin-top: 0.5em; text-align: right;">
<div>
<label>x offset <input id="shadowX" type="number" value="0" /></label>
<select id="shadowXUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
<div>
<label>y offset <input id="shadowY" type="number" value="0" /></label>
<select id="shadowYUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
<div>
<label>blur <input id="shadowBlur" type="number" value="0" min="0" /></label>
<select id="shadowBlurUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
<div>
<label>spread <input id="shadowSpread" type="number" value="0" min="0" /></label>
<select id="shadowSpreadUnit">
<option selected>px</option>
<option>em</option>
</select>
</div>
</div>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
box-shadow:
<input id="rawShadow" type="text" class="grow1" />
</label>
</div>
</div>
</div>
<!-- progress section -->
<div id="progress" class="group">
<h3>
<label>
<input id="isPresent" type="checkbox" checked />
<strong>track progress indication</strong>
</label>
</h3>
<!-- background section -->
<div id="background" class="subgroup">
<!-- normal section -->
<div id="normal" class="subgroup">
<label><strong>Background:</strong></label>
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
<div class="subgroup raw validationDisplay">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :hover section -->
<div id="hover" class="subgroupBorder">
<input id="progressBackgroundHoverCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="progressBackgroundHoverCheckbox">:hover</label>
<div class="colorPickerContainer invisible">
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
</div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
<!-- :active section -->
<div id="active" class="subgroupBorder">
<input id="progressBackgroundActiveCheckbox" type="checkbox" class="visibilityControl" /><label class="code" for="progressBackgroundActiveCheckbox">:active</label>
<div class="colorPickerContainer invisible">
<div class="colorPicker"><div id="backgroundColor"></div></div>
<label title="Check to use gradient.">
gradient
<input id="gradientCheckbox" type="checkbox" />
</label>
<div class="colorPicker"><div id="backgroundColor2"></div></div>
</div>
<div class="subgroup raw validationDisplay hidden">
<label class="flexVCentered">
background:
<input id="rawBackground" type="text" class="grow1" />
</label>
</div>
</div>
<div class="note" style="margin-top: 0.5em;">See explanation <a href="#explanation">below</a> how to make it work.</div>
</div>
</div>
</div>
<div id="generatedCssBlock" style="display: inline-block; vertical-align: top; width: 100%; max-width: 50em; margin-bottom: 1em;">
<label style="float: right;" title="Check to pin source code section on screen.">
<input id="stickCssBlockCheckbox" type="checkbox" autocomplete="off" />
pin
<span class="pinIcon">📌</span>
</label>
CSS:
<a id="downloadCssLink" href="javascript:void(0)" title="Save generated CSS to your computer.">download</a>
<button id="copyCssButton" class="fadedButton" title="Copy generated CSS to clipboard."><span class="copyIcon">copy</span></button>
<div style="margin: 0.5em 0 0.5em 0;">
<label title="CSS class name to use for styling input range sliders.">
Class name:
<span id="classNameValidationDisplay" class="validationDisplay" style="display: inline-block;">
<input id="className" class="code" style="width: 25em;" value="styled-slider" autocomplete="off" />
</span>
</label>
<button id="resetClassNameButton" class="fadedButton" title="Reset class name."><span class="resetIcon">reset</span></button>
</div>
<textarea id="styleDisplay" class="codeContainer" style="height: 70vh; width: 100%; margin-bottom: 1em;" readonly>change some styles</textarea>
<div id="download" class="dummy" style="margin-top: -20vh; height: 20vh;"></div>
JS for progress tracking:
<a class="no-external-link-icon" href="range-input.js" title="Download script." download target="_blank">download</a>
<button id="copyJSButton" class="fadedButton" title="Copy script to clipboard."><span class="copyIcon">copy</span></button>
<pre id="scriptDisplay" class="codeContainer">for (let e of document.querySelectorAll('input[type="range"].slider-progress')) {
e.style.setProperty('--value', e.value);
e.style.setProperty('--min', e.min == '' ? '0' : e.min);
e.style.setProperty('--max', e.max == '' ? '100' : e.max);
e.addEventListener('input', () => e.style.setProperty('--value', e.value));
}</pre>
Be sure to add the script to your page as explained <a href="#explanation">below</a>.
</div>
</div>
</div>
<div id="explanation" class="textblock notQuite100PercentWide">
<h2>Some more details</h2>
<p>
For progress indication to work, you need to add a script to your page, see <a href="#download">above</a>.
You can dowload, put it into your assets, and add it as external script:
</p>
<pre class="codeContainer" style="display: inline-block;"><script src="range-input.js"></script></pre>
<p>
or just copy-paste the contents right inside a <code><script></code> element.<br />
The idea is borrowed from
<a href="https://css-tricks.com/sliding-nightmare-understanding-range-input/#the-range-progress-fill-component"
title="A Sliding Nightmare: Understanding the Range Input"
target="_blank"
rel="noopener"><em>this great article</em></a>.
</p>
<p>
TODO: figure out how to neatly display focus outline.
Currently it looks ugly as fuck in general, that's why it is disabled by default.
</p>
<p>
Handle may be one pixel off center with respect to track. You'll have to wangjangle with it a bit.<br />
Handles are represented with an HTML element (like <code><div></code> or something),
apparently elements don't like to be at fractional coordinates.
</p>
<p>
<code>border-box</code>
<a href="https://developer.mozilla.org/docs/Web/CSS/box-sizing"
title="CSS: Cascading Style Sheets — box-sizing"
target="_blank"
rel="noopener">sizing model</a>
is used for handle and track,
i.e. specified width and height are generally what you get regardless of the border width.
(Unless border is dummy thick, but then jokes on you!)
</p>
</div>
<div class="credits" style="padding: 2em 0 1em 0;">
<div class="notQuite100PercentWide" style="text-align:center;">
View source code on <a class="no-external-link-icon" href="https://github.com/toughengineer/demo/tree/main/slider-styler" target="_blank" rel="noopener"><img class="icon" src="/demo/mark-github.svg" /> GitHub</a>
<span class="note">(Not recommended for sanity sake.)</span> |
<a class="no-external-link-icon" href="https://github.com/Simonwep/pickr" target="_blank" rel="noopener">Color picker</a> by <a class="no-external-link-icon" href="https://github.com/Simonwep" target="_blank" rel="noopener">Simonwep</a> |
<a class="no-external-link-icon" href="https://icons8.com/icon/43738/external-link" target="_blank" rel="noopener">External Link icon by Icons8</a><br />
<span class="note">These links will open in new tabs.</span>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@simonwep/pickr/dist/pickr.es5.min.js"></script>
<script src="slider-styler.min.js"></script>
<script src="range-input.js"></script>
</body>
</html>