美文网首页
vant2把单选框和复选框自定义为按钮样式

vant2把单选框和复选框自定义为按钮样式

作者: SleepWalkerLj | 来源:发表于2023-01-11 10:43 被阅读0次
单选效果.png

css样式

<style lang="less" scoped>
/deep/ .custom-radio-group,
.custom-checkbox-group {
    width: 100%;
    // 单选框,复选框文字样式
    .van-radio__label,
    .van-checkbox__label {
        text-align: center;
        margin-left: 0;
        height: 33px;
        line-height: 33px;
        background-color: #f6f8fa;
        width: 100%;
    }

    .van-radio,
    .van-checkbox {
        position: relative;
        border-radius: 4px;
        overflow: hidden;
    }

    // 去掉原本的勾选样式
    .van-radio__icon .van-icon,
    .van-checkbox__icon .van-icon {
        border: 0;
        display: none;
    }
    // 选中之后的文字颜色和背景色设置
    .van-radio__icon--checked + .van-radio__label,
    .van-checkbox__icon--checked + .van-checkbox__label {
        color: #617af0;
        background-color: #ecf0ff;
    }
}
</style>

使用

这个是单选框的使用方法,多选框把class改为class="custom-checkbox-group"就行了

<van-field name="radio" label="性别">
    <template #input>
        <van-radio-group
            class="custom-radio-group"
            v-model="formData.sex"
        >
            <van-row gutter="10">
                <van-col span="6">
                    <van-radio name="0">男 </van-radio>
                </van-col>
                <van-col span="6">
                    <van-radio name="1">女 </van-radio>
                </van-col>
            </van-row>
        </van-radio-group>
    </template>
</van-field>

角标效果

角标效果.png
<style lang="less" scoped>
/deep/ .custom-radio-group,
.custom-checkbox-group {
    width: 100%;
    // 单选框,复选框文字样式
    .van-radio__label,
    .van-checkbox__label {
        text-align: center;
        margin-left: 0;
        height: 33px;
        line-height: 33px;
        background-color: #f6f8fa;
        width: 100%;
    }

    .van-radio,
    .van-checkbox {
        position: relative;
        border-radius: 4px;
        overflow: hidden;
    }

    // 去掉原本的勾选样式
    .van-radio__icon .van-icon,
    .van-checkbox__icon .van-icon {
        border: 0;
        display: none;
    }
    // 选中之后的文字颜色和背景色设置
    .van-radio__icon--checked + .van-radio__label,
    .van-checkbox__icon--checked + .van-checkbox__label {
        color: #617af0;
        background-color: #ecf0ff;
    }
    .van-radio__icon--checked,.van-checkbox__icon--checked {
        .van-icon{
            display: block;
            position: absolute;
            right: -15px;
            bottom: -20px;
            width: 30px;
            height: 30px;
            border-radius: 0;
            -webkit-transform: rotate(50deg);
            transform: rotate(50deg);
            background-color: #617af0;
        }
    }
    .van-icon-success:before{
        position: absolute;
        left: -1px;
        bottom: 9px;
        -webkit-transform: rotate(-60deg);
        transform: rotate(-60deg);
        font-size: 10px;
    }
}
</style>

相关文章

  • Egret eui学习

    eui 按钮、单选框、复选框 用法学习

  • 自定义ListView item包含checkbox实现单选和多

    CheckBox本为复选框,仍然可以当单选框用 自定义ListView item中包含一个textview 和ch...

  • 《GUI设计禁忌》2.1 使用了错误的控件

    2.1.1 复选框和单选框 1: 错把复选框当做单选框2: 错把单选框当做复选框 当位置有限时,可以用以下方式替代...

  • 微信小程序—— 1 基础

    组件: 视图容器 图标文件文本域复选框 按钮单选框 图片...

  • Form表单用法

    标签用于为用户输入创建 HTML 表单,表单能够包含input元素,比如文本字段、复选框、单选框、提交按钮等等。表...

  • 表单

    文本框: 密码框: 单选框: 复选框: 作为按钮: 不可点击的按钮: 可提交按钮: 多行文本域: (cols="3...

  • HTML属性的含义

    标签用于为用户输入创建HTML表单表单能够包含 input 元素 比如文本字段、复选框、单选框、提交按钮等等表单还...

  • v-model 绑定复选框,单选框

    单选框 复选框 下拉框 绑定值上面介绍的单选按钮、复选框和选择列表在单独使用或单的 模式下 v-model 绑定的...

  • 做一个好看的单选和多选框(CSS查漏补缺)

    文: jack同学 我们知道,单选框和复选框的样式几乎改变不了,原因是由于它们是可替换元素,样式更改权限较小,所以...

  • 原生JS表单美化

    1.表单美化—单选框 html结构 css样式 js代码 2.表单美化—复选框 html结构 css样式 js代码...

网友评论

      本文标题:vant2把单选框和复选框自定义为按钮样式

      本文链接:https://www.haomeiwen.com/subject/zdybcdtx.html