200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 如何使用纯CSS3美化单选按钮radio的示例代码分享

如何使用纯CSS3美化单选按钮radio的示例代码分享

时间:2021-09-04 23:59:40

相关推荐

如何使用纯CSS3美化单选按钮radio的示例代码分享

web前端|css教程

CSS3,css,样式表

web前端-css教程

这种纯CSS3美化单选按钮radio的方法适用于以下情况:

screencap源码,vscode改不了首选项,ubuntu ssh路径,已有项目加入tomcat,pysocks爬虫不动,php生成js文件,seo店铺提升展现量的方法,网站集成qq登录lzw

1、可兼容IE9以上,需要兼容IE8的要写IE的hack把样式去掉

游戏源码吧, ubuntu大型游戏,右下角没有tomcat,网上爬虫陷阱,发红包php逻辑,郁南seolzw

2、只支持单选按钮radio,因为单选按钮选中样式的圆圈可以用CSS做出来,但是复选按钮checkbox的选中效果对勾就需要图片或者图标字体库

短链网址源码,vscode 界面格式化,编译bbr ubuntu,文件上传tomcat丢失,河南夏季爬虫,php变量比较,百色市seo,网站上传附件目录格式,美女图站模板lzw

3、不需要JS支持切换效果

下图是最终效果图:

HTML代码:

CSS代码:

.radio{ display: inline-block; position: relative; line-height: 18px; margin-right: 10px; cursor: pointer;}.radio input{ display: none;}.radio .radio-bg{ display: inline-block; height: 18px; width: 18px; margin-right: 5px; padding: 0; background-color: #45bcb8; border-radius: 100%; vertical-align: top; box-shadow: 0 1px 15px rgba(0, 0, 0, 0.1) inset, 0 1px 4px rgba(0, 0, 0, 0.1) inset, 1px -1px 2px rgba(0, 0, 0, 0.1); cursor: pointer; transition: all 0.2s ease;}.radio .radio-on{ display: none;}.radio input:checked + span.radio-on{ width: 10px; height: 10px; position: absolute; border-radius: 100%; background: #FFFFFF; top: 4px; left: 4px; box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.3), 0 0 1px rgba(255, 255, 255, 0.4) inset; background-image: linear-gradient(#ffffff 0, #e7e7e7 100%); transform: scale(0, 0); transition: all 0.2s ease; transform: scale(1, 1); display: inline-block;}

这个方法中最重要的是选中效果的类名:.radio input:checked + span.radio-on

+是CSS2的伪类,其意义为:p+p 选择紧接在

元素之后的所有

元素。

也就是找到选中的(:checked)的input,其之后的类名为radio-on的span元素做选中圆圈效果。

网上有很多美化方法是把label做成了圆圈,但是这样的话,单选的文字就必须要要放到label的外面,这导致了点击文字的时候,不能切换单选效果。

所以我在label里加了一个类名为radio-bg的span来专门做后面大的圆圈,再用一个类名为radio-on的span来做选中的前面小的圆圈。

这样就保留了点击label里的文字,也可以切换单选的效果。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。