当前位置:网站首页>修改checkbox样式
修改checkbox样式
2022-07-17 05:25:00 【guizi0809】
checkbox默认样式
以谷歌浏览器为例
<div class="box">
<input type="checkbox" />篮球
<input type="checkbox" />足球
<input type="checkbox" />乒乓球
</div>
自带默认margin: 3px 3px 3px 4px

默认框框样式
width: 10px;
height: 10px;
border-radius: 2px;
border: 1px solid rgb(118, 118, 118);
box-sizing: border-box;

选中时的样式
修改checkbox默认样式
可以设置尺寸和边距
input[type="checkbox"] {
width: 20px;
height: 20px;
margin: 0;
}

使用appearance: none隐藏默认checkbox的框框,重写框框样式
原理:通过绝对定位覆盖原多选框
input[type="checkbox"] {
width: 20px;
height: 20px;
margin: 0 4px 0 0;
appearance: none;
position: relative;
}
示例一:
/** 未被选中的样式*/
input[type="checkbox"]::before {
content: "";
position: absolute;
top: 0;
left: 0;
background: #fff;
width: 100%;
height: 100%;
border: 1px solid #d9d9d9;
border-radius: 4px;
}
/** 选中的样式 */
input[type="checkbox"]:checked::before {
content: "\2713"; /* 2713表示勾勾* */
background-color: #fff;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 1px solid #7d7d7d;
border-radius: 4px;
color: #7d7d7d;
font-size: 20px;
font-weight: bold;
text-align: center;
line-height: 20px;
}
效果图:
示例二:
/** 未被选中的样式*/
input[type="checkbox"] {
width: 20px;
height: 20px;
margin: 0 4px 0 0;
appearance: none;
position: relative;
background: wheat;
border-radius: 50%;
}
/** 选中的样式*/
input[type="checkbox"]:checked::before {
content: "";
background: orange;
position: absolute;
top: 25%;
left: 25%;
width: 50%;
height: 50%;
border: none;
border-radius: 50%;
}
效果图:
边栏推荐
- 网络知识-03 数据链路层-PPPoE
- Spark3.x入门到精通-阶段七(spark动态资源分配)
- Review of 4705 NLP
- TSN security protocol (802.1qci)
- Spark3.x entry to proficiency - stage 6 (RDD advanced operator explanation & Illustration & shuffle tuning)
- What is the difference between Samsung series NAND flash?
- Flink入门到实战-阶段一(集群安装&使用)
- Application of A2B audio bus in intelligent cockpit
- Network knowledge-05 transport layer TCP
- 网络知识-04 网络层-ICMP协议
猜你喜欢

环境变量和文件夹放置位置

2021-10-25 浏览器兼容遇到的问题

Product Case Interviews

Xiaoyi and you talk about how to realize c-v2x HIL test in v2x test series (2022 version)

Jenkins如何设置邮箱自动发送邮件?

如何选择合适的模型

【量化笔记】波动volatility相关技术指标以其含义

60. Clear cache

Understanding of v2x test series v2x phase II application scenario

持续集成如何进行Jenkins管理?
随机推荐
Slackware 14.2 installing KDE 5 plasma
Install SQL developer for Galaxy Kirin desktop operating system v10sp1 (x86)
Typescript (I)
Hypothesis testing
MySql02 函数substr mod 视图view
MySql
Solution to the conflict between security automatic login and anti CSRF attack
Administrator blocked this app from running
一文带你了解SOA接口测试
Spark3.x入门到精通-阶段七(spark动态资源分配)
Flink入门到实战-阶段一(集群安装&使用)
SQL刷题总结 SQL Leetcode Review
Review of 4121 Computer System for Data Science
SSM整合
Promote trust in the digital world
小怿和你聊聊V2X测试系列之 如何实现C-V2X HIL测试(2022版)
A2B音频总线在智能座舱中的应用
Review of 4246 Algorithms for Data Science
Sword finger offer question brushing record - offer 06 Print linked list from end to end
Execute shell script under Linux to call SQL file and transfer it to remote server