在标签上用鼠标按下后,复选框将突出显示.我想删除这个效果.到目前为止,我尝试preventDefault()了偶数onMouseDown事件,但它不会影响突出显示.
(上部复选框突出显示/更暗 - 对标签上的mousedown事件产生影响)
除了在点击标签后没有突出显示复选框的开/关行为应保持不受影响.
额外信息:我无法通过修改复选框的样式来实现它,因为下一步我想要仅对标签的一部分使用无突出显示行为(标签内部的链接特别).
JSFiddle展示了这个问题:http://jsfiddle.net/o59udsLk/1/
您无法控制复选框对mousedown标签的影响,因为这是OS生成的效果.为此,您需要使用CSS样式和字体(可能)更改复选框的外观.
自定义CSS复选框:
body {
background: #e6e6e6;
}
h1 {
margin-top: 0;
}
.control-group {
display: inline-block;
width: 200px;
height: 210px;
margin: 10px;
padding: 30px;
text-align: left;
vertical-align: top;
background: #fff;
box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
.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;
}
/* Hover and focus states */
.control input:focus ~ .control__indicator {
background: #ccc;
}
/* Checked state */
.control input:checked ~ .control__indicator,
.control input:checked ~ .control__indicator:hover {
background: #2aa1c0;
}
/* Disabled state */
.control input:disabled ~ .control__indicator {
pointer-events: none;
opacity: .6;
background: #e6e6e6;
}
/* Check mark */
.control__indicator:after {
position: absolute;
display: none;
content: '';
}
/* Show check mark */
.control input:checked ~ .control__indicator:after {
display: block;
}
/* Checkbox tick */
.control--checkbox .control__indicator:after {
top: 4px;
left: 8px;
width: 3px;
height: 8px;
transform: rotate(45deg);
border: solid #fff;
border-width: 0 2px 2px 0;
}
/* Disabled tick colour */
.control--checkbox input:disabled ~ .control__indicator:after {
border-color: #7b7b7b;
}Run Code Online (Sandbox Code Playgroud)
<div class="control-group">
<h1>Checkboxes</h1>
<label class="control control--checkbox">First checkbox
<input type="checkbox" checked="checked"/>
<div class="control__indicator"></div>
</label>
<label class="control control--checkbox">Second checkbox
<input type="checkbox"/>
<div class="control__indicator"></div>
</label>
<label class="control control--checkbox">Disabled
<input type="checkbox" disabled="disabled"/>
<div class="control__indicator"></div>
</label>
<label class="control control--checkbox">Disabled & checked
<input type="checkbox" disabled="disabled" checked="checked"/>
<div class="control__indicator"></div>
</label>
</div>Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
905 次 |
| 最近记录: |