直到最近,YouTube使用了一个名为“paper-toggle-button”的标签。我的脚本使用了它,但由于YouTube已将其删除,我不得不使用普通的无聊复选框。
我不仅想要答案,我还想学习它是如何工作的。这个高级CSS对我来说很困扰。
我一直在尝试通过各种教程来复制它,这些教程以各种方式展示如何制作滑动切换按钮。但我对外观不满意。我希望它看起来尽可能接近YouTube的切换按钮。至少有一件事我已经学会了。下面的代码不需要任何图片,这很好。
这需要我没有的CSS高级知识。
这是一个例子,看起来很丑。因为例如必须手动将标签放在正确的位置。请参见.labelterm。当我无法使用此教程代码添加复选标记时,我放弃了。
这是一个例子,看起来很丑。因为例如必须手动将标签放在正确的位置。请参见.labelterm。当我无法使用此教程代码添加复选标记时,我放弃了。
<!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;
/*background: rgba(0, 0, 0, 0.1);*/
border-radius: 20px;
transition: all 0.3s ease;
}
.slidinggroove:after {
position: absolute;
content: "";
width: 28px;
height: 28px;
border-radius: 50%;
background: #fff;
/*background: rgba(255, 255, 255, 0.2);*/
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>