Created
July 11, 2023 11:49
-
-
Save digitalbricks/5f66364b8e35971a66af5ad9c51b57df to your computer and use it in GitHub Desktop.
Demo of checkbox styles for a sliding switch layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Checkbox switch</title> | |
<style> | |
.checkswitch{ | |
display: flex; | |
justify-content: flex-start; | |
align-items: center; | |
} | |
.checkswitch span{ | |
margin-left: 0.5rem; | |
} | |
.checkswitch input{ | |
appearance: none; | |
width: 2rem; | |
height: 1rem; | |
display: block; | |
position: relative; | |
} | |
.checkswitch input::before, | |
.checkswitch input::after{ | |
content: ''; | |
position: absolute; | |
display: block; | |
border-radius: 1rem; | |
pointer-events: none; | |
top: 0; | |
left: 0; | |
cursor: pointer; | |
} | |
.checkswitch input::before{ | |
background-color: #DB4251; | |
width: 100%; | |
height: 100%; | |
transition: background 0.3s ease; | |
box-shadow: inset 0px 2px 2px 0px rgba(0,0,0,0.1); | |
} | |
.checkswitch input::after{ | |
background-color: #e4e4e4; | |
height: 1rem; | |
width: 1rem; | |
transition: transform 0.2s ease; | |
box-shadow: 0px 2px 2px 0px rgba(0,0,0,0.1); | |
} | |
.checkswitch input:checked::after{ | |
transform: translateX(1rem); | |
} | |
.checkswitch input:checked::before{ | |
background-color: #42DB65; | |
} | |
</style> | |
</head> | |
<body> | |
<label for="checky" class="checkswitch"> | |
<input type="checkbox" name="checky" id="checky"> | |
<span> | |
Label | |
</span> | |
</label> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment