自定义单选按钮和复选框按钮

一.单选按钮

1.效果图

在这里插入图片描述

2.代码

<style>
	/*去除代码默认样式*/
	input{
		display: none;
	}
		/*在label前面添加自定义单选按钮*/
	label:before{
		content: "";
		width: 5px;
		height: 5px;
		display: inline-block;
		border: 1px solid red;
		border-radius: 50%;
		padding: 2px;
	}
		/*当input被选中时,对应label前面加样式*/
	input:checked+label:before{
		background: black;
		background-clip:content-box; /*图片裁切*/
	}
	</style>
</head>
<body>
	<!--input要与label绑定-->
	<input  id="man" type="radio" name="gender" checked="checked">
	<label for="man"></label>
	
	<input id="woman" type="radio" name="gender">
	<label for="woman"></label>
</body>

二.复选按钮

1. 效果图

在这里插入图片描述

2.代码

<style>
	input{
		display: none;
	}
	/*用label画出复选框的框*/
	label{
		display: inline-block;
		width: 10px;
		height: 10px;
		border:1px solid #ccc;
		position: relative;
	}
	/*选中时label变色*/
	input:checked+label{
		border-color: #888;
	}
	/*当复选框被选中时,相应label前添加勾的短边*/
	input:checked+label:before{
		content: "";
		width: 2px;
		height: 8px;
		display: inline-block;
		background: black;
		transform:rotate(-30deg);/*选中的勾的短边*/
		position: absolute;
		top:4px;
		left: 0px;
	}
	/*当复选框被选中时,相应label后添加勾的长边*/
	input:checked+label:after{
		content: "";
		width: 2px;
		height: 10px;
		display: inline-block;
		background: black;
		transform:rotate(30deg);	/*勾的长边*/
		position: absolute;
		top:0px;
		left: 5px;
	}
	</style>
</head>
<body>
	<input id="chinese" type="checkbox" name="cbox">
	<label for="chinese"></label>语文

	<input  id="match" type="checkbox" name="cbox">
	<label for="match"></label>数学

	<input  id="English" type="checkbox" name="cbox">
	<label for="English"></label>英语
</body>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值