Created
December 30, 2024 02:33
-
-
Save ssghost/bdcb98ea8c7b0bf37efb72b2eee18cbe to your computer and use it in GitHub Desktop.
This file contains hidden or 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" /> | |
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<title>Vite App</title> | |
<style> | |
body { | |
padding: 1rem; | |
} | |
</style> | |
</head> | |
<body> | |
<label class="label"> | |
<div class="checkbox-comp"> | |
<input type="checkbox" /> | |
<svg | |
aria-hidden="true" | |
viewBox="0 0 24 24" | |
fill="none" | |
xmlns="http://www.w3.org/2000/svg" | |
> | |
<path | |
d="M5.5 12.5L9.5 16.5L18.5 7.5" | |
stroke="black" | |
stroke-width="2" | |
stroke-linecap="round" | |
stroke-linejoin="round" | |
/> | |
</svg> | |
</div> | |
This is the label | |
</label> | |
<style> | |
.label { | |
display: flex; | |
align-items: center; | |
} | |
.checkbox-comp { | |
position: relative; | |
display: inline-block; | |
border-radius: 0.25rem; | |
border: 1px rgba(0, 0, 0, 0.3) solid; | |
transition: background 100ms ease-in-out; | |
user-select: none; | |
margin-right: 0.5rem; | |
height: 16px; | |
width: 16px; | |
} | |
.checkbox-comp:has(:focus-visible) { | |
outline: 2px solid rgba(0, 0, 255, 0.4); | |
outline-offset: 2px; | |
} | |
.checkbox-comp > input { | |
appearance: none; | |
all: unset; | |
height: 16px; | |
width: 16px; | |
} | |
.checkbox-comp > svg { | |
position: absolute; | |
top: 0; | |
left: 0; | |
height: 16px; | |
width: 16px; | |
} | |
.checkbox-comp > input ~ svg > path { | |
stroke-dashoffset: 0; | |
stroke-dasharray: 100%; | |
transition: stroke-dashoffset 100ms ease-in-out; | |
} | |
.checkbox-comp:has(input:checked) { | |
background: rgba(0, 0, 255, 0.05); | |
} | |
.checkbox-comp > input:not(:checked) ~ svg > path { | |
stroke-dashoffset: 100%; | |
} | |
</style> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment