CSS radio美化

参考文献

使用纯CSS美化radio和checkbox


在参考文献的基础上进行改进

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
* { /*所有控件*/
	margin: 0px; /*外边距为0*/
	padding: 0px; /*内边距为0*/
	outline: none; /*不显示轮廓线*/
	font-family: Microsoft YaHei; /*设置字体*/
	box-sizing: border-box; /* 定宽和定高 */
}
.div-radio {
	height: 40px;
	width: 300px;
	line-height: 40px;
	margin-left: 80px;
	margin-top: 20px;
	border: 1px red solid;
}
.magic-radio {
	display: none; /* 隐藏自带的radio */
}
.magic-radio+label {
	position: relative;
	padding-left: 25px; /* label与radio左端偏离量,与before left相同 */
	cursor: pointer;
}
.magic-radio+label:hover:before {
	border-color: #3e97eb;
}
.magic-radio+label:before { /* 圆形框 */
	position: absolute;
	top: 0;
	bottom: 0;
	left: -25px; /* 与padding-left相同 */
	right: 0;
	margin: auto;
	width: 15px;
	height: 15px;
	border-radius: 50%;
	content: '';
	border: 1px solid #c0c0c0;
}
.magic-radio+label:after { /* 中心圆点 */
	position: absolute;
	display: none;
	content: '';
	top: 0;
	left: -23.5px;
	bottom: 0;
	right: 0;
	margin: auto;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background-color: #3e97eb;
}
.magic-radio:checked+label:before {
	border-color: #3e97eb;
}
.magic-radio:checked+label:after {
	display: block;
}
.magic-radio[disabled]+label, .magic-radio[disabled]+label:before {
	cursor: not-allowed; 
	color: #c0c0c0;
	border-color: #c0c0c0;
}
.magic-radio:checked[disabled]+label:before {
	border-color: #c9e2f9;
}
.magic-radio:checked[disabled]+label:after {
	background: #c9e2f9;
}
</style>

<title>Insert title here</title>
</head>
<body>
	<div class="div-radio">
		<input id="male" name="sex" type="radio" class="magic-radio"value="男"/>
		<label for="male">男</label>  
		<input id="female" name="sex" type="radio" class="magic-radio" value="女" disabled/>
		<label for="female">女</label>
	</div>
</body>
</html>
效果

未选中


选中后



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值