CSS3 checkbox美化效果
分类:实例代码
CSS3 checkbox美化效果属于前端实例代码,有关更多实例代码大家可以查看。
本章节分享一段代码实例,它利用css3对checkbox复选框进行了简单的美化效果。
点击复选框的时候有动画过渡效果。
代码实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.pipipi.net/" /> <title>犀牛前端部落</title> <style type="text/css"> .checkbox-value { position: relative; height: 30px; line-height: 30px; padding-left: 30px; overflow: hidden; display:block; cursor:pointer; } .checkbox-value:before { transition: all 0.5s ease-in; content: ""; width: 20px; height: 20px; position: absolute; border: 2px solid rgb(0,0,0); border-radius: 4px; left: 0; top: 5px; background: #fff; overflow: hidden; cursor: pointer; } .checkbox-value:after { border: none; transition: all 0.2s ease-in; } .checkboxcon { position: relative; height: 30px; overflow: hidden; box-sizing: border-box; display: table; vertical-align: middle; } .checkbox { display: inline-block; width: 0; height: 0; opacity: 0; *width: 20px; *height: 20px; position: absolute; top: 5px; } .checkboxcon input[type=checkbox]:checked + .checkbox-value:before { transition: all 0.5s ease-in; content: ""; width: 20px; height: 20px; position: absolute; border: 2px solid rgba(0,0,0,0.5); border-radius: 4px; left: 0; top: 5px; background: #000; overflow: hidden; cursor: pointer; } .checkboxcon input[type=checkbox]:checked + .checkbox-value:after { cursor: pointer; margin-top: 5px; margin-left: 8px; content: ""; width: 4px; height: 9px; border-right: 1px solid #fff; border-bottom: 1px solid #FFF; transform: rotate(45deg); position: absolute; left: 0; top: 5px; transition: all 0.2s ease-out; } </style> <script type="text/javascript"></script> </head> <body> <label class="checkboxcon"> <input class="checkbox" type="checkbox" /> <span class="checkbox-value">请选择</span> </label> </body> </html>
上面的代码非常简单,更多内容可以参阅相关阅读。
相关阅读:
(1).:before参阅CSS E:before/E::before伪对象选择符一章节。
(2).transition参阅CSS3 transition一章节。
(3).border-radius参阅CSS3 border-radius圆角一章节。
(4).box-sizing参阅CSS3 box-sizing一章节。
(5).transform参阅CSS3 transform一章节。
(6).label标签参阅<label>标签的for属性一章节。
(7).[type=checkbox]参阅CSS E[att="val"]属性选择符一章节。
CSS3 checkbox美化效果,这样的场景在实际项目中还是用的比较多的,关于CSS3 checkbox美化效果就介绍到这了。