Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 327d731

Browse filesBrowse files
committed
Add webkit-appearance checkbox.
1 parent 1e0589d commit 327d731
Copy full SHA for 327d731

File tree

Expand file treeCollapse file tree

2 files changed

+94
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+94
-0
lines changed
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ with.
1010

1111
## My JavaScript Demos - I Love JavaScript!
1212

13+
* [Using CSS Webkit-Appearance To Style Checkbox ::after Pseudo-Element](https://bennadel.github.io/JavaScript-Demos/demos/webkit-appearance-checkbox/)
1314
* [Retrofitting Theming Into A Legacy App Using LESS CSS And CSS Custom Properties](https://bennadel.github.io/JavaScript-Demos/demos/legacy-theming/)
1415
* [Effortless Custom Form Input Styling With Webkit Appearance None](https://bennadel.github.io/JavaScript-Demos/demos/webkit-appearance/)
1516
* [Using CSS Counters To Apply Custom Labels To An HTML List](https://bennadel.github.io/JavaScript-Demos/demos/css-counters/)
Collapse file
+93Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
7+
<title>
8+
Using CSS Webkit-Appearance To Style Checkbox ::after Pseudo-Element
9+
</title>
10+
</head>
11+
<body>
12+
13+
<h1>
14+
Using CSS Webkit-Appearance To Style Checkbox ::after Pseudo-Element
15+
</h1>
16+
17+
<style type="text/css">
18+
19+
label {
20+
align-items: center ;
21+
cursor: pointer ;
22+
display: flex ;
23+
}
24+
25+
label input {
26+
margin: 0px 0px 0px 10px ;
27+
}
28+
29+
/*
30+
Only apply custom styles to browsers that are going to support them. This is
31+
important because even old browsers will apply SOME of these CSS properties;
32+
and, we don't want to create Frankenstein checkboxes.
33+
*/
34+
@supports ( appearance: none ) or ( -moz-appearance: none ) or ( -webkit-appearance: none ) {
35+
36+
input.custom {
37+
appearance: none ;
38+
-moz-appearance: none ;
39+
-webkit-appearance: none ;
40+
border: 2px solid currentcolor ;
41+
border-radius: 52px 52px 52px 52px ;
42+
color: #999999 ;
43+
padding: 2px 2px 2px 2px ;
44+
transition-duration: 300ms ;
45+
transition-property: border-color, color ; /* Safari needed border-color. */
46+
transition-timing-function: ease ;
47+
width: 52px ;
48+
}
49+
50+
input.custom:checked {
51+
color: #ff3366 ;
52+
}
53+
54+
/*
55+
NOTE: The ::after pseudo-selector is being applied to the INPUT itself,
56+
not a parent element. I had no idea this even works! I can't find any
57+
documented support on this (just some StackOverflow threads).
58+
*/
59+
input.custom::after {
60+
background-color: currentcolor ;
61+
border-radius: 10px 10px 10px 10px ;
62+
content: "" ;
63+
display: block ;
64+
height: 18px ;
65+
transform: translateX( 0% ) ;
66+
transition: transform 300ms ease ;
67+
width: 45% ;
68+
}
69+
70+
input.custom:checked::after {
71+
transform: translateX( 121% ) ;
72+
}
73+
74+
}
75+
76+
</style>
77+
78+
<p>
79+
<label for="checkbox1">
80+
Default checkbox:
81+
<input id="checkbox1" type="checkbox" />
82+
</label>
83+
</p>
84+
85+
<p>
86+
<label for="checkbox2">
87+
Webkit-Appearance checkbox:
88+
<input id="checkbox2" type="checkbox" class="custom" />
89+
</label>
90+
</p>
91+
92+
</body>
93+
</html>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.