Recently, YouTube discontinued the use of a tag called "paper-toggle-button". As a result, I had to switch to using a regular checkbox in my script. However, I am interested not just in finding a quick fix but in truly understanding how it all works. It is frustrating that despite my efforts, the complex CSS still eludes me.
I have been following tutorials on creating sliding toggle buttons in different ways to replicate YouTube's toggle button appearance. Unfortunately, none of them have matched my expectations. One positive aspect is that the code below does not require any images, which is a plus.
https://i.sstatic.net/GWuc9.png
This task demands a deep level of CSS expertise, which I currently lack.
Here is an example of my attempt, although it looks quite unattractive due to having to manually position the label correctly. Refer to .labelterm. The point at which I got stuck was trying to incorporate a checkmark into this tutorial code.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
<title>Awesome checkbox</title>
<style type="text/css">
.mylabel {
position: relative;
display: block;
width: 60px;
height: 30px;
margin-bottom: 15px;
}
.mylabel input {
display: none;
}
.slidinggroove {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: #ababab;
border-radius: 20px;
transition: all 0.3s ease;
}
.slidinggroove:after {
position: absolute;
content: "";
width: 28px;
height: 28px;
border-radius: 50%;
background: #fff;
top: 1px;
left: 1px;
transition: all 0.3s ease;
}
input:checked + .slidinggroove {
background: #5fcf80;
}
input:checked + .slidinggroove:after {
transform: translateX(30px);
}
.labelterm {
margin-left: 65px;
font-size: 16px;
color: #222;
font-family: "Roboto", sans-serif;
position: relative;
top: 5px;
}
</style>
</head>
<body>
<div class="mylabel">
<input type="checkbox" id="coding">
<div class="slidinggroove"></div>
<label class="mylabel" for="coding" name="skills"><p class="labelterm">Test</p></label>
</div>
</body>
</html>