编写点击能变色的单选框

创建一个盒子,并创建两个label,在label里面创建radio


<div class="box">
        <label>请选择性别</label>
        <label class="radio-box">
            <input type="radio" name="sex">
            <span class="radio"></span>
            <span></span>
        </label>
        <label class="radio-box">
            <input type="radio" name="sex">
            <span class="radio"></span>
            <span></span>
        </label>
    </div>

编写radio的样式


<style>
		/*单选框居中*/
        * {
            text-align: center;
        }
        
        /*设置单选框宽高、设置成行盒、边框、将边框变成圆、鼠标放上去变手*/
        .radio-box .radio {
            width: 12px;
            height: 12px;
            display: inline-block;
            border: 1px solid aqua;
            border-radius: 50px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="box">
        <label>请选择性别</label>
        <label class="radio-box">
            <input type="radio" name="sex">
            <span class="radio"></span>
            <span></span>
        </label>
        <label class="radio-box">
            <input type="radio" name="sex">
            <span class="radio"></span>
            <span></span>
        </label>
    </div>
</body>

设置点击变色样式


<style>
        /*单选框居中*/
        * {
            text-align: center;
        }
        
        /*设置单选框宽高、设置成行盒、边框、将边框变成圆、鼠标放上去变手*/
        .radio-box .radio {
            width: 12px;
            height: 12px;
            display: inline-block;
            border: 1px solid aqua;
            border-radius: 50px;
            cursor: pointer;
        }
        
        /*设置伪元素内容为空、伪元素33设置成块、设置宽高、伪元素背景色、块设置成圆、调边距*/
        .radio-box input:checked+.radio::after {
            content: "";
            display: block;
            width: 6px;
            height: 6px;
            background-color: red;
            border-radius: 50px;
            margin-left: 3px;
            margin-top: 3px;
        }
        
        /*点击radio变色*/
        .radio-box input:checked+.radio {
            border-color: red;
        }
        
        /*设置成空*/
        .radio-box input[type="radio"] {
            display: none;
        }
    </style>
</head>

<body>
    <div class="box">
        <label>请选择性别</label>
        <label class="radio-box">
            <input type="radio" name="sex">
            <span class="radio"></span>
            <span></span>
        </label>
        <label class="radio-box">
            <input type="radio" name="sex">
            <span class="radio"></span>
            <span></span>
        </label>
    </div>
</body>

效果图203019694.PNG)

在这里插入图片描述在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值