【发布时间】:2016-09-06 15:41:46
【问题描述】:
我现在正在为我大学的网络工程课程做一个项目。我们必须创建某种学校管理网站,并且现在只允许使用纯 HTML 和 CSS,但我们在没有类和 id 的 CSS 中工作的限制是,只允许使用选择器。
现在我想在我们的页面上添加一个切换按钮,我找到了这个网站 (https://proto.io/freebies/onoff/),您可以在其中创建自己的切换按钮。但是您收到的代码适用于我不允许使用的类,所以我尝试更改代码以便它只使用选择器但它不起作用。 也许有人可以在这里帮助我理解我的错误(除了复制代码 sn-p 而不是解决问题)。
div:last-of-type {
position: relative;
width: 67px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
input[type="checkbox"] {
display: none;
}
label {
display: block;
overflow: hidden;
cursor: pointer;
height: 22px;
padding: 0;
line-height: 22px;
border: 2px solid #CCCCCC;
border-radius: 22px;
background-color: #FA1212;
transition: background-color 0.3s ease-in;
}
label:before {
content: "";
display: block;
width: 22px;
margin: 0px;
background: #FFFFFF;
position: absolute;
top: 0;
bottom: 0;
right: 43px;
border: 2px solid #CCCCCC;
border-radius: 22px;
transition: all 0.3s ease-in 0s;
}
input[type="checkbox"]:checked + label {
background-color: #28CF25;
}
input[type="checkbox"]:checked + label,
input[type="checkbox"]:checked +label:before {
border-color: #28CF25;
}
input[type="checkbox"]:checked + label:before {
right: 0px;
}
<div>
<input type="checkbox" name="onoffswitch" checked>
<label for="myonoffswitch"></label>
</div>
【问题讨论】: