css--美化html选择框

 

 经过css修饰过的个人信息表格,其中单选框消失了,取而代之的是直接在label上选择,多选框也一样。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

        .form {
            width: 500px;
            height: 400px;
            background-color: pink;
            margin: 0 auto;
            border-radius: 20px;
            padding-left: 50px;
        }

        .form h1 {
            text-align: center;
            padding-top: 50px;
        }

        input[type="radio"] ,input[type="checkbox"]{
            display: none;
        }

        input[type="radio"]+label ,input[type="checkbox"]+label{
            
            background: linear-gradient(#d3cdf1 10%,#d6dbff 50%,#d3cdf1);
			border-radius: 10px;padding: 0 10px;margin-left: 15px;
			border:solid 2px #b5c5fc;
            color:#55557f;
        }

        input[type="radio"]:checked+label ,input[type="checkbox"]:checked+label{
            color:#4862A8;
            background: linear-gradient(lightpink 10%,#fff 50%,lightpink);
        }
        #name {
            width: 300px;
            height: 30px;
            margin-left: 20px;
        }

        .an {
            margin-left: 100px;
            border: 2px solid blue;
            font-weight: 700;
        }
        .an:hover {
            background-color: aqua;
        }
    </style>
</head>
<body>
    <form action="" class="form">
        <h1 class="h1">个人信息</h1>
        <label for="name">姓名:</label><input type="text" id="name" placeholder="请输入你的姓名">
        <br><br>
        <label for="">性别:</label>
        <input type="radio" id="men" name="sex"><label for="men">男</label>
        <input type="radio" id="women" name="sex"><label for="women">女</label>
        <br><br>
        <label for="">兴趣:</label>
        <input type="checkbox" id="sing"><label for="sing">唱歌</label>
        <input type="checkbox" id="dance"><label for="dance">跳舞</label>
        <input type="checkbox" id="yundong"><label for="yundong">运动</label>
        <br><br>
        <input type="submit" class="an" value="提交"><input type="reset" class="an" value="重置">
    </form>
</body>
</html>

其中对选择框修饰的代码是:

input[type="radio"] ,input[type="checkbox"]{
            display: none;
        }

        input[type="radio"]+label,input[type="checkbox"]+label{
            
            background: linear-gradient(#d3cdf1 10%,#d6dbff    50%,#d3cdf1);
			border-radius: 10px;padding: 0 10px;
            margin-left: 15px;
			border:solid 2px #b5c5fc;color:#55557f;
        }

        input[type="radio"]:checked+label,input[type="checkbox"]:checked+label{
            color:#4862A8;background: linear-gradient(lightpink 10%,#fff 50%,lightpink);
        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值