html - 如何更好地设置复选框的样式?Toggleclass 不起作用,它似乎需要一个 id - 我怎样才能在检查之前使这个复选标记图标不可见
问题描述
我正在尝试设置复选框的样式并实现了更改背景颜色的方法 - 见下文
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<style>
body,
html {
font-family: "Lato", monospace;
font-size: calc(1rem + 1vw);
}
.label__checkbox {
display: none;
}
.label__checkbox i.icon {
visibility: hidden;
font-size: calc(9rem + 1vw);
color: transparent;
}
.label__check {
display: inline-block;
border-radius: 3%;
border: 2px solid rgba(0, 0, 0, 0.1);
background: white;
vertical-align: middle;
margin-right: 20px;
width: 10em;
height: 2em;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
.label__check i.icon {
opacity: 0.2;
font-size: calc(9rem + 1vw);
color: white;
}
.label__check:hover {
border: 5px solid rgba(0, 0, 0, 0.2);
}
.label__checkbox:checked + .label__text .label__check {
-webkit-animation: check 0.1s cubic-bezier(0.895, 0.03, 0.685, 0.22) forwards;
animation: check 0.1s cubic-bezier(0.895, 0.03, 0.685, 0.22) forwards;
}
.label__checkbox:checked + .label__text .label__check .icon {
opacity: 1;
transform: scale(0);
color: white;
-webkit-text-stroke: 0;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
@-webkit-keyframes check {
100% {
width: 10em;
height: 2em;
background: #00d478;
border: 0;
opacity: 1;
}
}
@keyframes check {
100% {
width: 10em;
height: 2em;
background: #00d478;
border: 0;
opacity: 1;
}
}
.normal {
font-size: 15px;
line-height: 20px;
color: blueviolet;
}
.bigger {
font-size: 25px;
color: forestgreen;
}
</style>
<body>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="center"> <label class="label">
<input class="label__checkbox" type="checkbox" />
<span class="label__text">
<span class="label__check">
<i class="fa fa-check icon"></i>
</span>
</span> </label>
</body>
</html>
我的问题是未选中该框时会显示复选标记图标。这给某些人(显然)造成了一些混乱。我一直在尝试使用 toggleclass 和 jquery 来用其他东西替换图像,但我无法让它工作。我也刚刚尝试使初始复选标记不可见,但由于某种原因,我试图隐藏可见性的尝试不起作用。有什么想法或想法吗?
谢谢你的时间。
解决方案
推荐阅读
- javascript - 对于 HTML 表单,是否使用 JavaScript?- 2020 年
- javascript - 如何使用 selenium 向下滚动屏幕?
- vue.js - Vuex:向对象添加动态属性而不触发现有属性上的观察者
- ruby - 无法启动 Firefox 浏览器并在 RubyMine 中使用 RSpec 运行测试
- vue.js - 如何有效地为 Vuex 状态属性的所有子属性创建 getter 和 setter?
- javascript - 将页面标题的第一个单词与 Javascript 中的数组进行比较
- python - 是否可以通过从 Excel 文件中导入数据来创建词云?
- angular - Angular 9 材质对话框在关闭时返回未定义
- string - Java 变量只初始化一次
- flutter - 如何在颤动中从 ListView.builder 循环遍历 ListTile