input单选框和复选框改变自带的颜色和背景色

65 篇文章 2 订阅

单选框:

<!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>
        .box {
            width: 300px;
            height: 300px;
            margin: 100px auto;
        }
        input[type="radio"]::before {
            position: relative;
            content: "";
            top: -1px;
            left: -1px;
            width: 17px;
            height: 17px;
            display: block;
            border-radius: 50%;
            background-color: #fff;
            border: 1px solid #6b4bff;
            z-index: 5;
        }
        input[type="radio"]:checked::after {
            position: relative;
            content: "";
            bottom: 15px;
            left: 4px;
            width: 9px;
            height: 9px;
            display: block;
            border-radius: 50%;
            visibility: visible;
            background-color: #6b4bff;
            z-index: 6;
        }
    </style>
</head>
<body>
    <div class="box">
        <input type="radio">
    </div>
</body>
</html>

效果图:

复选框:

<!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>
        .box {
            width: 300px;
            height: 300px;
            margin: 100px auto;
        }
        input[type=checkbox]{
            cursor: pointer;
            position: relative;
            width: 15px;
            height: 15px;
            font-size: 14px;
        }
        input[type=checkbox]::after{
            position: absolute;
            top: 0;
            border: none;
            /* background-color: #ff670c; */
            color: #fff;
            width: 15px;
            height: 15px;
            display: inline-block;
            visibility: visible;
            padding-left: 0px;
            text-align: center;
            content: ' ';
            border-radius: 1px
        }       
        input[type=checkbox]:checked::after{
            background-color: #6b4bff;
            border-color: #6b4bff;
            content: "✓";
            font-size: 12px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="box">
        <input type="checkbox">
        <input type="checkbox">
    </div>
</body>
</html>

效果图:

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
在uni-app单选框复选框可以使用checkbox组件来实现。在基础用法下,uni-app会使用内置的默认参数来显示checkbox的样式和状态。然而,这种用法不能满足实际业务场景的需求,因为复选框通常以组的形式出现,即使组只有一个选项。为了引入组的概念,uni-app还提供了一个checkbox-group组件来使用。基本用法是将checkbox组件放置在checkbox-group组件内,如下所示: <checkbox-group> <checkbox /> 篮球 <checkbox /> 足球 <checkbox /> 网球 </checkbox-group> 可以通过checkbox组件的disabled属性来控制复选框是否可选或取消选。当复选框处于disabled状态时,复选框的样式将变灰,用户无法进行选或取消选操作。disabled属性的类型为Boolean,默认值为false。 为了修改checkbox的样式,可以通过设置相应的CSS样式来实现。比如,可以使用uni-checkbox类来修改复选框的外观。uni-checkbox-input类可以用来设置复选框状态的样式。在样式,可以设置border-radius属性来改变复选框的圆角,color属性来改变复选框颜色,border属性来设置状态的边框,background属性来设置状态的背景色,以及其他一些样式属性来调整复选框的大小和位置。 综上所述,uni-app提供了方便的单选框复选框组件,可以通过设置属性和样式来满足不同的需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值