纯CSS 自定义单选框与多选框

很多时候需要自定义单选,多选,用css自定义来帮助我们解决这个问题

兄弟们老规矩先上图

 代码html

<label class="noselect checkLabel">
	<input type="checkbox"><i>✓</i>复选框
</label><br>
<label class="checkLabel">
	<input type="checkbox" checked><i>✓</i>复选框
</label><br>
<label class="checkLabel">
	<input type="checkbox" disabled><i>✓</i>复选框禁用
</label><br>
<label class="checkLabel">
	<input type="checkbox" disabled checked><i>✓</i>复选框禁用已选
</label><br>
<label class="checkLabel">
	<input type="radio" name="abc"><i>✓</i>单选框
</label><br>
<label class="checkLabel">
	<input type="radio" name="abc" checked><i>✓</i>单选框
</label><br>
<label class="checkLabel">
	<input type="radio" name="abc" disabled><i>✓</i>单选框禁用
</label><br>
<label class="checkLabel">
	<input type="radio" name="def" disabled checked><i>✓</i>单选框禁用已选
</label><br>

css

.checkLabel {
	font-size: 12px;
	cursor: pointer;
}

.checkLabel i {
	font-size: 12px;
	font-style: normal;
	display: inline-block;
	width: 12px;
	height: 12px;
	text-align: center;
	line-height: 12px;
	color: rgba(255, 255, 255, 0);
	vertical-align: middle;
	margin: -2px 2px 1px 0px;
	border: #2489c5 1px solid;
	border-radius: 50%;
}

.checkLabel input[type="checkbox"],
input[type="radio"] {
	display: none;
}

.checkLabel input[type="checkbox"]:checked+i,
input[type="radio"]:checked+i {
	background: #2489c5;
	color: rgba(255, 255, 255, 1);
}

.checkLabel input[type="checkbox"]:disabled+i,
input[type="radio"]:disabled+i {
	border-color: #ccc;
}

.checkLabel input[type="checkbox"]:checked:disabled+i,
input[type="radio"]:checked:disabled+i {
	background: #ccc;
}
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently not supported by any browser */
}

拿走不谢,点个赞!!!

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值