Stylish css button
Before seeing the code, take a look at my video for experience how it will perform at your device.
YouTube link -Click me
Copy and paste in your editor and enjoy
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Body Background</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: grid;
place-items: center;
height: 100vh;
position: relative;
overflow: hidden;
}
body::before {
content: "";
position: absolute;
top: -100%;
width: 100%;
height: 50%;
background: rgba(10, 10, 10, 1);
transition: 0.8s;
}
body::after {
content: "";
position: absolute;
bottom: -100%;
width: 100%;
height: 50%;
background: rgba(10, 10, 10, 1);
transition: 0.8s;
}
input {
appearance: none;
height: 25px;
width: 65px;
background: rgba(241, 241, 242, 1);
border-radius: 20px;
box-shadow: 0 0 0 2px #CDCDCD,
0 0 5px 1px #B6B7BC inset;
position: relative;
z-index: 9;
outline-width: 5px;
outline-style: solid;
outline-offset: 3px;
outline-color: rgba(193, 193, 193, 1);
}
input::before {
content: "";
position: absolute;
height: 25px;
width: 23px;
border-radius: 50%;
background: linear-gradient(to bottom, #0CA0FF, #20C7FF), linear-gradient(to right, #096ED0, #094E8F);
background-blend-mode: multiply;
transition: 1.5s;
z-index: 11;
box-shadow: 0 0 5px rgba(9, 41, 137, 1) inset;
}
input:checked::before {
width: 65px;
border-radius: 20px;
}
input::after {
content: "";
position: absolute;
height: 26px;
width: 26px;
border-radius: 50%;
background: linear-gradient(#28C9FF, #086381), linear-gradient(rgba(8, 9, 129, 1), rgba(79, 81, 255, 1));
top: calc(50% - 14px);
background-blend-mode: overlay;
left: 1px;
transition: 1.5s;
box-shadow: 0 0 5px 0px rgba(9, 131, 210, 1) inset;
z-index: 11;
top: -0.5px;
}
input:checked::after {
left: calc(75% - 6px);
height: 18px;
width: 18px;
top: calc(50% - 9px);
}
.span {
position: absolute;
font-weight: bolder;
font-size: 8px;
left: 185px;
top: calc(50% - 8px);
color: rgba(197, 197, 197, 1);
transition: 0.3s 0.5s;
z-index: 10;
}
input:checked+span {
opacity: 0;
transition: 0.3s 0s;
}
.span+span {
position: absolute;
font-weight: bold;
font-size: 9px;
left: 153px;
top: calc(50% - 8px);
color: rgba(223, 223, 223, 1);
opacity: 0;
z-index: 10;
}
span {
user-select: none;
}
input:checked+.span+span {
opacity: 1;
transition: 0.3s 0.3s;
}
body:has(.box input:checked)::before {
top: 0;
}
body:has(.box input:checked)::after {
bottom: 0;
}
@media screen and (min-height:1821px) {
.span {
left: 500px;
}
.span+span {
left: 463px;
}
}
</style>
</head>
<body>
<div class="box">
<input type="checkbox" name="" id="">
<span class="span">Light</span><span>dark</span>
</div>
</body>
</html>
Hope you will give great review
Thanks
@dhawneetg
Comments
Post a Comment