<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>选中标签forcheck</title>
<script src="./js/jquery-2.1.1.min.js"></script>
<style type="text/css">
.riskSources label {
cursor: pointer;
position: relative;
display: inline-block;
width: 49px;
height:49px;
border: 1px solid transparent;
}
/**
* 按钮透明
* @type {String}
*/
#riskCheck {
opacity: 0;
}
/**
* checkbox选中样式
* @type {String}
*/
#riskCheck:checked + i {
border-color: blue;
color: blue;
border-width:2px;
}
/**
* i标签的大小
*/
.riskSources i {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 1px solid transparent;
text-align: center;
line-height: 36px;
border-radius: 50%;
margin-left:-3px;
margin-top:-3px;
}
/**
* 选中状态,span(三角形)样式
* @type {String}
*/
#riskCheck:checked + i + span {
display: inline-block;
position: relative;
width: 15px;
padding-top: -80px;
height: 15px;
float: right;
margin-top: 14px;
margin-right: -5px;
border-radius: 50%;
background-color: blue;
border-width:2px;
}
#riskCheck:checked +i+ span:before,
#riskCheck:checked +i + span:after {content: '';pointer-events: none;position: absolute;color: white;border: 1px solid;background-color: white;}
#riskCheck:checked + i + span:before {width: 1px;height: 1px;left: 25%;top: 50%;transform: skew(0deg,50deg);}
#riskCheck:checked + i + span:after{width: 3px;height: 1px;left: 45%;top: 42%;transform: skew(0deg,-50deg);}
</style>
<script >
function test(){
alert($('#riskCheck').is(':checked'));
}
</script>
</head>
<body>
<div class="riskSources" style="
background: url(./ziyuan3.png) no-repeat;
border-radius:34px;
height: 51px;
width:51px;
background-size: 100% 100%;
">
<label>
<input id="riskCheck" type="checkbox" value="cbEticket" style="
background-size: 100% 100%;
border: 2px solid blue;
width: 100%;
">
<i></i>
<span></span>
</label>
</div>
<button onclick="test()">测试吧</button>
</body>
</html>
未选中效果:
点击后效果:
图片源: