欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

css 实现checkbox 选中 显示红色对钩,如何实现? 有大用

css 实现checkbox 选中 显示红色对钩,如何实现?

 我来答  举报
chenfei2341
2015-06-16 · TA获得超过832个赞

这个单纯使用css是无法实现的。

一般的话,我们实现这个效果是通过将checkbox的visibility设置为hidden,然后为checkbox添加label,对label进行样式设置,图片替换来实现你需要的效果。

建议将label里面内容替换为图片提升兼容性。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
#checkbox-1 {
   display: none; 
   visibility:hiiden;
}
  
#checkbox-1 + label { 
    color: blue;
}
  
#checkbox-1:checked + label {
    color: red;
}
</style>
</head>
 
<body>
<p><input type="checkbox" id="checkbox-1"><label for="checkbox-1">✔☑</label></p>
</body>
</html>
ankle425
2012-01-17 · TA获得超过120个赞
<style type="text/css"> .label_on { border:2px solid red; } <///对div#checkbox下的input[checkbox]进行遍历 { var ifchecked=$("#


来自 https://zhidao.baidu.com/question/368099281.html


普通分类: