html input单选样式,input单选框美化——自定义样式

本文介绍了两种方法来美化HTML中的Radio按钮。方法一是通过CSS隐藏默认样式并添加自定义背景图片;方法二是利用label和伪元素创建选中效果。这两种方法都能实现个性化的Radio按钮设计,提升用户体验。
摘要由CSDN通过智能技术生成

方法一:

给input添加

-webkit-appearance: none;

隐藏默认样式。然后添加自己的样式就好了。

例如:

fcecaa27ea5212ceb9bf034c36bfbf34.gif

.radioBox input{

-webkit-appearance: none;

width: 20px;

height: 20px;

padding: 0;

background-color: #fff;

border: 1px solid #c9c9c9;

border-radius: 50%;

outline: none;

margin-right: 22px;

cursor: pointer;

}

fcecaa27ea5212ceb9bf034c36bfbf34.gif

选中时的样式:

.radioBox input:checked{

background: url(‘../img/checkBox_selected.png‘) no-repeat center;

}

效果:

2df80e52d0dcd9372e36035dff91cfb8.png

方法二:

添加label,给label添加样式,隐藏input

html:

fcecaa27ea5212ceb9bf034c36bfbf34.gif

fcecaa27ea5212ceb9bf034c36bfbf34.gif

css

fcecaa27ea5212ceb9bf034c36bfbf34.gif

.radioBox input{

display: none;

}

.radioBox label{

cursor: pointer;

position: relative;

}

.radioBox label::before{

display: inline-block;

content: "";

width: 16px;

height: 16px;

border-radius: 50%;

border: 2px solid rgba(193, 200, 211, 1);

margin-right: 6px;

vertical-align: middle;

}

/* 选中 */

.radioBox input:checked+label::after{

display: inline-block;

content: "";

width: 12px;

height: 12px;

border-radius: 50%;

position: absolute;

left: 4px;

bottom: 4px;

background-color: rgba(56, 85, 127, 1);

}

fcecaa27ea5212ceb9bf034c36bfbf34.gif

效果:

bf4ea4f9c4b667079b2a60b6d70633fd.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值