当前位置: 首页 > news >正文

css:button实现el-radio效果

先看最终效果:

​​​请添加图片描述
请添加图片描述

思路

一、

首先准备好按钮内容:const a = ['one','two','three']
将按钮循环展示出来,并设置一些样式,将按钮背景透明:

<button v-for="(item,index) in a" :key="index">{{ item }}</button>button {width: 100px;height: 40px;border-radius: 20px;border: 1px solid red;background-color: transparent;
}

请添加图片描述

二、

在外面包裹一个div,设置背景颜色,border-radius与按钮一致(按钮边框和背景透明,这样背景是什么颜色/边框,按钮就会是什么颜色/边框):

 <div class="container">  <button v-for="(item,index) in a" :key="index">{{ item }}</button></div>.container {margin:40px;border: 1px solid transparent;display: inline-block;padding: 0;border-radius: 20px;height: 40px;background-color: #ECEFEE;
}
button {width: 100px;height: 40px;border-radius: 20px;border: 1px solid transparent;background-color: transparent;
}

请添加图片描述

三、

最后加上选中效果,因为是单选所以必须保证每次只能选中一个,动态绑定class:

<div class="container">  <button v-for="(item,index) in a" :key="index" :class="radio==item?'yes':''" @click="handleClick(item)">{{ item }}</button>
</div>const radio = ref('one') // 默认选中
const handleClick = (value) =>{radio.value = value
}.container{margin:40px;border: 1px solid transparent;display: inline-block;padding: 0;border-radius: 20px;height: 40px;background-color: #ECEFEE;
}
button{width: 100px;height: 40px;border-radius: 20px;border: 1px solid transparent;background-color: transparent;
}
.yes {background: red;color: white;
}

over!!!🎉🎉🎉

http://www.lryc.cn/news/211388.html

相关文章:

  • 算法工程师-机器学习-数据科学家面试准备4-ML系统设计
  • git重装后如何连接以前项目
  • 【java学习—十】TreeSet集合(5)
  • JMeter的使用,傻瓜式学习【上】
  • 主定理(一般式)
  • WLAN的组网架构和工作原理
  • 使用OBS Browser+访问华为云OBS存储【Windows】
  • C++总结(3):类的动态内存分配、异常、类型转换运算符
  • 折半搜索(meet in the middle)
  • 【机器学习】loss损失讨论
  • LeetCode 779. 第K个语法符号【递归,找规律,位运算】中等
  • java try throw exception finally 遇上 return break continue造成异常丢失
  • 设计模式——装饰器模式(Decorator Pattern)+ Spring相关源码
  • MATLAB R2018b详细安装教程(附资源)
  • GEE错误——影像加载过程中出现的图层无法展示的解决方案
  • 读图数据库实战笔记03_遍历
  • QT如何检测当前系统是是Windows还是Uninx或Mac?以及是哪个版本?
  • Maven配置阿里云中央仓库settings.xml
  • 由浅入深C系列八:如何高效使用和处理Json格式的数据
  • 多媒体应用设计师 第16章 多媒体应用系统的设计和实现示例
  • golang平滑重启库overseer实现原理
  • 用Python定义一个函数,用递归的方式模拟汉诺塔问题
  • 二手的需求
  • 大厂面试题-JVM为什么使用元空间替换了永久代?
  • 基本微信小程序的驾校宝典系统-驾照考试系统
  • 02、SpringCloud -- Redis和Cookie过期时间刷新功能
  • 【报错】kali安装ngrok报错解决办法(zsh: exec format error: ./ngrok)
  • <学习笔记>从零开始自学Python-之-常用库篇(十三)内置小型数据库shelve
  • Redis快速上手篇七(集群-六台虚拟机)
  • LeetCode 301. 删除无效的括号【字符串,回溯或BFS】困难