-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSS-custom-checkbox.html
98 lines (85 loc) · 2.56 KB
/
CSS-custom-checkbox.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Custom CheckBox</title>
<style>
.container {
display: grid;
place-items: center;
margin-top: 250px;
}
.chk-container {
display: block;
position: relative;
user-select: none;
padding-left: 40px;
margin-bottom: 12px;
font-size: 22px;
/* -webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none; */
}
.chk-container input {
/* Hide the original input checkbox */
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.chk-container .checkmark {
/* create custom checkbox */
position: absolute;
left: 0;
top: 0;
width: 25px;
height: 25px;
background: crimson;
cursor: pointer;
}
.chk-container:hover input~.checkmark {
/* change checkbox BG color on hover */
background-color: springgreen;
}
.chk-container input:checked~.checkmark {
background-color: deepskyblue;
/* change checkbox BG on checked */
}
/* Create the checkmark/indicator (hidden when not checked) */
.chk-container .checkmark:after {
content: " ";
position: absolute;
display: none;
}
.chk-container input:checked~.checkmark::after {
display: block;
/* Show the checkmark when checked */
}
/* Style the checkmark/indicator */
.chk-container .checkmark::after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid whitesmoke;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
</style>
</head>
<body>
<div class="container">
<label class="chk-container" for="checkbox1">
<input type="checkbox" checked="checked" id="checkbox1">
<span class="checkmark"></span>
Remember Me
</label>
<!--
Each label must have a for attribute value exactly matching the id of the checkbox it is meant to activate.
-->
</div>
</body>
</html>