CSS自定义美化单选按钮样式

直接上效果图:

HTML代码:

<div style="display:flex;">
	<div class="omgui-radio">
		<input type="radio" value="1" id="showon" name="isshow" checked="checked" />
		<label for="showon">显示</label>
	</div>
	<div class="omgui-radio">
		<input type="radio" value="0" id="showoff" name="isshow" />
		<label for="showoff">隐藏</label>
	</div>
</div>

CSS代码:

.omgui-radio {
	margin:5px;
	margin-right:2rem;
}

.omgui-radio input[type="radio"] {
	opacity: 0;
}

.omgui-radio label {
	position: relative;
	cursor: pointer;
}

.omgui-radio label::before {
	content: '';
	position: absolute;
	left: -24px;
	border-radius: 50%;
	width: 20px;
	height: 20px;
	border: 1px solid #999;
}

.omgui-radio label::after {
	content: '';
	position: absolute;
	left: -20px;
	top: 4px;
	border-radius: 50%;
	width: 12px;
	height: 12px;
	transform: scale(0);
}
/* + 是兄弟选择器,获取选中后的label元素*/
.omgui-radio input+label::before {
	border-color: #ccc;
}

.omgui-radio input+label::after {
	background-color: #ccc;
	transform: scale(1);
	transition: all .3s;
}
.omgui-radio input:checked+label::before {
	border-color: #19B395;
}

.omgui-radio input:checked+label::after {
	background-color: #19B395;
	transform: scale(1);
	transition: all .3s;
}

.omgui-radio input:hover+label::before {
	border-color: #19B395;
}

.omgui-radio input:focus+label::before {
	box-shadow: 0 0 6px #19B395;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值