gpt4 book ai didi

html - 想要在纯 css 中复制 youtube 的自动播放切换按钮

转载 作者:行者123 更新时间:2023-12-04 03:37:34 34 4
gpt4 key购买 nike

直到最近 youtube 使用了一个名为“paper-toggle-button”的标签。我的脚本使用了它,但自从 youtube 删除它后,我不得不用一个普通的无聊复选框来解决。我不只是想要一个答案。我想了解它是如何工作的。令我烦恼的是,这个高级 CSS 还没有为我点击。

我一直在尝试通过以各种方式展示如何制作滑动切换按钮的教程来复制它。但我对外观不满意。我希望它看起来尽可能靠近 youtube 的切换按钮。至少我学到了一件事。下面的代码不需要任何图片,这很好。

picture of the toggle button

这需要我没有的 css 高级知识。

这是一个例子,它看起来很丑。因为它必须例如手动将标签放在正确的位置。参见 .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>

最佳答案

以下是我将如何解决此问题以实现所示图片的外观:

.slidinggroove::before{
position: absolute;
left: 7px;
top: 50%;
transform: translateY(-7px);
width: 20px;
height: 20px;
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f00c";
display: block;
color: #fff;
}

您必须将图标库作为字体导入,我建议使用 FontAwesome,如此处的工作片段所示:

.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;
}

.slidinggroove:before {
position: absolute;
left: 7px;
top: 50%;
transform: translateY(-7px);
width: 20px;
height: 20px;
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f00c";
display: block;
color: #fff;
}

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;
}
<html>

<head>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
<title>Awesome checkbox</title>
</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>

它的工作方式如下,您创建一个伪元素,其内容将是 fontawesome 图标的 unicode。然后您可以完全控制悬停它(字体大小、颜色、...)。

关于html - 想要在纯 css 中复制 youtube 的自动播放切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66600215/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com