input radio单选框样式优化

  HTML代码:

  

 1 <form>
 2       <div>
 3         <input id="item1" type="radio" name="item" value="水果" checked>
 4         <label for="item1"></label>
 5         <span style="margin-left: 10px">水果</span>
 6       </div>
 7       <div>
 8         <input id="item2" type="radio" name="item" value="饮料">
 9         <label for="item2"></label>
10         <span style="margin-left: 10px">饮料</span>
11       </div>
12     </form>

 

 

  css代码:

  

 1 div {
 2   position: relative;
 3   line-height: 30px;
 4 }
 5 
 6 input[type="radio"] {
 7   width: 20px;
 8   height: 20px;
 9   opacity: 0;
10 }
11 
12 label {
13   position: absolute;
14   left: 5px;
15   top: 8px;
16   width: 20px;
17   height: 20px;
18   border-radius: 50%;
19   border: 1px solid #999;
20 }
21 
22 /*设置选中的input的样式*/
23 /* + 是兄弟选择器,获取选中后的label元素*/
24 input:checked+label {
25   background-color: #006eb2;
26   border: 1px solid #006eb2;
27 }
28 
29 input:checked+label::after {
30   position: absolute;
31   content: "";
32   width: 5px;
33   height: 10px;
34   top: 3px;
35   left: 6px;
36   border: 2px solid #fff;
37   border-top: none;
38   border-left: none;
39   transform: rotate(45deg)
40 }

 

  效果图:

  

 

转载于:https://www.cnblogs.com/nelsonlei/p/7878154.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值