自定义radio与checkbox的样式

4 篇文章 0 订阅

由于input中的radio与checkbox的样式比较单一而且样式不是很美观,所以我们一般都想定义一个自己比较喜欢的样式,偶然发现这种自定义方法比较容易理解,在此特意分享一下:

首先是自定义单选框样式及复选框样式具体代码如下:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>split方法</title>
		<style type="text/css">
			*{
				margin: 0;
				padding: 0;
			}
			.one{
				margin: 50px;
			}
			.one input[type='radio']{
				margin-left: 2px;
				margin-right: 2px;
				display: none;
			}
			.one input[type='radio']+label:before{
				content: '';
				display: inline-block;
				width: 10px;
				height: 10px;
				margin-right: 5px;
				border-radius: 100%;
				vertical-align: middle;
				border: 2px solid #E4E4E4;
				background: #F9F9F9;
			}
			.one input[type='radio']:checked+label:before{
				background: #777777;
			}
			
			.one input[type='checkbox']{
				display: none;
			}
			.one input[type='checkbox']+label:before{
				content: '';
				width: 10px;
				height: 10px;
				vertical-align: middle;
				margin-right: 5px;
				display: inline-block;
				background: #F9F9F9;
				border: 2px solid #CCCCCC;
			}
			.one input[type='checkbox']:checked+label:before{
				background: lightcoral;
			}
			
		</style>
	</head>
	<body>
		<!--radio-->
		<div class="one" id="one">
			<input type="radio" name="pay" id="p_yes" class="rdo"/>
			<label for="p_yes">是</label>
			<input type="radio" name="pay" id="p_no" class="rdo"/>
			<label for="p_no">否</label>
		</div>
		<!--checkbox-->
		<div class="one">
			<input type="checkbox" name="fav" id="book" class="rdo"/>
			<label for="book">Book</label>
			<input type="checkbox" name="fav" id="run" class="rdo"/>
			<label for="run">Run</label>
			<input type="checkbox" name="fav" id="music" class="rdo"/>
			<label for="music">Music</label>
			<input type="checkbox" name="fav" id="ktv" class="rdo"/>
			<label for="ktv">KTV</label>
			<input type="checkbox" name="fav" id="swimming" class="rdo"/>
			<label for="swimming">swimming</label>
		</div>	
	</body>
</html>
效果图如下:



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值