【发布时间】:2017-02-18 21:01:27
【问题描述】:
我做了一个复选框样式,它使用标签标签。见下文
是否仍然可以在没有标签标签的情况下保留整个复选框的 CSS?所以我只有输入标签,但仍然是 CSS。 这是复选框的CSS。
.control {
font-size: 18px;
position: relative;
display: block;
margin-bottom: 15px;
padding-left: 30px;
cursor: pointer;
}
.control input {
position: absolute;
z-index: -1;
opacity: 0;
}
.control__indicator {
position: absolute;
top: 2px;
left: 0;
width: 20px;
height: 20px;
background: #e6e6e6;
}
.control--radio .control__indicator {
border-radius: 50%;
}
.control:hover input ~ .control__indicator,
.control input:focus ~ .control__indicator {
background: #ccc;
}
.control input:checked ~ .control__indicator {
background: orange;
}
.control:hover input:not([disabled]):checked ~ .control__indicator,
.control input:checked:focus ~ .control__indicator {
background: #ecb53a;
}
.control input:disabled ~ .control__indicator {
pointer-events: none;
opacity: .6;
background: #e6e6e6;
}
.control__indicator:after {
position: absolute;
display: none;
content: '';
}
.control input:checked ~ .control__indicator:after {
display: block;
}
.control--checkbox .control__indicator:after {
top: 4px;
left: 8px;
width: 3px;
height: 8px;
transform: rotate(45deg);
border: solid black;
border-width: 0 2px 2px 0;
}
<label class="control control--checkbox">
<input type="checkbox"/>
<div class="control__indicator"></div>
</label>
希望大家能帮帮我。
【问题讨论】:
-
没有label标签的你试过了吗?
-
请澄清您的具体问题或添加其他详细信息以准确突出您的需要。正如目前所写的那样,很难准确地说出你在问什么。
-
我要问的是我是否仍然可以拥有带有标签标签的复选框的样式,而没有标签标签。
-
如果您只想要 css 解决方案,我认为您不能,因为如果您点击
<div class="control__indicator"></div>,您不会选择复选框。使用 for inside 标签,您可以单击并激活复选框。 -
我只想要
<input type="checkbox"/>有一个类并且仍然拥有它现在拥有的 CSS。