我们知道css可以美化前端页面,本文我们就和大家分享纯Css代码美化checkbox复选框、radios单选框和滑动按钮的简单方法,希望能帮助到大家。
效果预览
1. 复选框
<html> <head> <style type="text/css"> .switch { margin: 20px 20px 0 0; display: flex; align-items: center; width: auto; } .checkbox-input { display: none } .checkbox { -webkit-transition: background-color 0.3s; transition: background-color 0.3s; background-color: #fff; border: 1px solid #d7d7d7; border-radius: 3px; width: 16px; height: 16px; vertical-align:middle; margin: 0 5px; } .checkbox-input:checked+.checkbox { background-color: #57ad68; } .checkbox-input:checked+.checkbox:after { content: "\2714"; display: inline-block; height: 100%; width: 100%; color: #fff; text-align: center; line-height: 16px; font-size: 12px; box-shadow: 0 0 4px #57ad68; } </style> </head> <body> <label class="switch"> <input class="checkbox-input" id="checkbox" type="checkbox" name="demo-checkbox1"> <label class="checkbox" for="checkbox"></label> <span>Hello</span> </label> </body> </html>
2. 单选框
<html> <head> <style type="text/css"> .switch { display: flex; align-items: center; width: auto; float: left; } .radio-beauty-container .radio-beauty { width: 16px; height: 16px; box-sizing: border-box; display: inline-block; border: 1px solid #d7d7d7; margin: 0 5px; border-radius: 50%; transition: 0.2s; } .radio-beauty-container input[type="radio"]:checked+.radio-beauty { border: solid 1px green; padding: 3px; background-color: green; background-clip: content-box; box-shadow: inset 0 0 1px rgba(0,128,0, 0.2), 0 0 3px green; } </style> </head> <body> <p class="radio-beauty-container"> <label class="switch"> <span class="radio-name">radio2</span> <input type="radio" name="radioName" id="radioName2" hidden/> <label for="radioName2" class="radio-beauty"></label> </label> <label class="switch"> <span class="radio-name">radio3</span> <input type="radio" name="radioName" id="radioName3" hidden/> <label for="radioName3" class="radio-beauty"></label> </label> </p> </body> </html>
3. 滑动按钮
<html> <head> <style type="text/css"> .switch-slide-label { display: block; width: 34px; height: 18px; background: #ccc; border-radius: 30px; cursor: pointer; position: relative; -webkit-transition: 0.3s ease; transition: 0.3s ease; } .switch-slide-label:after { content: ''; display: block; width: 16px; height: 16px; border-radius: 100%; background: #fff; box-shadow: 0 1px 1px rgba(0, 0, 0, .1); position: absolute; left: 1px; top: 1px; -webkit-transform: translateZ(0); transform: translateZ(0); -webkit-transition:0.3s ease; transition:0.3s ease; } .switch-slide input:checked+label { background: #34bf49; transition: 0.3s ease; } .switch-slide input:checked+label:after { left: 17px; } </style> </head> <body> <p class="radio-beauty-container"> <label class="switch-slide"> <input type="checkbox" id="menu-right" hidden> <label for="menu-right" class="switch-slide-label"></label> </label> </p> </body> </html>
最简洁的代码美化复选框、单选框和滑动按钮
效果预览
1. 复选框
<html> <head> <style type="text/css"> .switch { margin: 20px 20px 0 0; display: flex; align-items: center; width: auto; } .checkbox-input { display: none } .checkbox { -webkit-transition: background-color 0.3s; transition: background-color 0.3s; background-color: #fff; border: 1px solid #d7d7d7; border-radius: 3px; width: 16px; height: 16px; vertical-align:middle; margin: 0 5px; } .checkbox-input:checked+.checkbox { background-color: #57ad68; } .checkbox-input:checked+.checkbox:after { content: "\2714"; display: inline-block; height: 100%; width: 100%; color: #fff; text-align: center; line-height: 16px; font-size: 12px; box-shadow: 0 0 4px #57ad68; } </style> </head> <body> <label class="switch"> <input class="checkbox-input" id="checkbox" type="checkbox" name="demo-checkbox1"> <label class="checkbox" for="checkbox"></label> <span>Hello</span> </label> </body> </html>
2. 单选框
<html> <head> <style type="text/css"> .switch { display: flex; align-items: center; width: auto; float: left; } .radio-beauty-container .radio-beauty { width: 16px; height: 16px; box-sizing: border-box; display: inline-block; border: 1px solid #d7d7d7; margin: 0 5px; border-radius: 50%; transition: 0.2s; } .radio-beauty-container input[type="radio"]:checked+.radio-beauty { border: solid 1px green; padding: 3px; background-color: green; background-clip: content-box; box-shadow: inset 0 0 1px rgba(0,128,0, 0.2), 0 0 3px green; } </style> </head> <body> <p class="radio-beauty-container"> <label class="switch"> <span class="radio-name">radio2</span> <input type="radio" name="radioName" id="radioName2" hidden/> <label for="radioName2" class="radio-beauty"></label> </label> <label class="switch"> <span class="radio-name">radio3</span> <input type="radio" name="radioName" id="radioName3" hidden/> <label for="radioName3" class="radio-beauty"></label> </label> </p> </body> </html>
3. 滑动按钮
<html> <head> <style type="text/css"> .switch-slide-label { display: block; width: 34px; height: 18px; background: #ccc; border-radius: 30px; cursor: pointer; position: relative; -webkit-transition: 0.3s ease; transition: 0.3s ease; } .switch-slide-label:after { content: ''; display: block; width: 16px; height: 16px; border-radius: 100%; background: #fff; box-shadow: 0 1px 1px rgba(0, 0, 0, .1); position: absolute; left: 1px; top: 1px; -webkit-transform: translateZ(0); transform: translateZ(0); -webkit-transition:0.3s ease; transition:0.3s ease; } .switch-slide input:checked+label { background: #34bf49; transition: 0.3s ease; } .switch-slide input:checked+label:after { left: 17px; } </style> </head> <body> <p class="radio-beauty-container"> <label class="switch-slide"> <input type="checkbox" id="menu-right" hidden> <label for="menu-right" class="switch-slide-label"></label> </label> </p> </body> </html>
相关推荐:
HTML页面中的的美化checkbox_html/css_WEB-ITnose
使用jquery与图片美化checkbox和radio控件的代码(打包下载)_jquery
以上是纯Css代码美化checkbox复选框、radios单选框和滑动按钮简单方法的详细内容。更多信息请关注PHP中文网其他相关文章!

我最近找到了一种动态更新任何产品图像的颜色的解决方案。因此,只有一种产品之一,我们可以以不同的方式对其进行着色以显示

在本周的综述中,灯塔在第三方脚本上阐明了灯光,不安全的资源将在安全站点上被阻止,许多国家连接速度

有很多分析平台可帮助您跟踪网站上的访问者和使用数据。也许最著名的是Google Analytics(广泛使用)

文档负责人可能不是网站上最迷人的部分,但是其中所处的内容对于您的网站的成功也一样重要

当您看到一些称为super()的JavaScript时,在子类中,您会使用super()调用其父母的构造函数和超级。访问它的


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Dreamweaver Mac版
视觉化网页开发工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。