您的位置:首页 > Web前端 > CSS

纯CSS改写checkbox样式,让复选框看起来更舒服一些

2015-10-11 20:53 597 查看
系统自带的checkbox样式,呵呵

特别是在手机上,得拿放大镜看,改它!

纯CSS的,利用了label,看代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link href="../css/bootstrap.css" rel="stylesheet">
<style type="text/css">
.mycheck {
width: 25px;
margin: 20px 100px;
position: relative;
}
.mycheck input[type=checkbox] {
visibility: hidden;
}
.mycheck label {
cursor: pointer;
position: absolute;
width: 25px;
height: 25px;
top: 0;
left: 0;
background: #fff;
border:2px solid #ccc;
-moz-border-radius: 3px;      /* Gecko browsers */
-webkit-border-radius: 3px;   /* Webkit browsers */
border-radius:3px;            /* W3C syntax */
}
.mycheck label:after {
opacity: 0;
content: '';
position: absolute;
width: 9px;
height: 5px;
background: transparent;
top: 6px;
left: 6px;
border: 2px solid #333;
border-top: none;
border-right: none;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.mycheck label:hover::after {
opacity: 0.5;
}
.mycheck input[type=checkbox]:checked + label:after {
opacity: 1;
}
</style>
</head>
<body>
<h3>Checkbox</h3>
<div class="mycheck">
<input type="checkbox" value="1" id="checkbox1" name="" />
<label for="checkbox1"></label>
</div>
</body>
</html>


如果你有CSS相关基础的话,还可以做进一步改动,比如颜色,边线等

同样可以做出单选框radio来。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: