前端小技巧(二):评分效果css版
2017-12-22 15:56
155 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .box{ width:205px; height:42px; position: relative; } label{ width:42px; float: right; height: 42px; margin-left: -1px; } label span{ width:40px; height: 40px; border:1px solid #0b4b5a; display: inline-block; position: relative; z-index: 2; } label:hover dfn{ display: block; z-index:1; } label input{ display: none; } label input:checked~dfn{ display: block; } label dfn{ width:100px; height: 42px; line-height:42px; text-align: center; position: absolute; background: #f00283; display: none; top:0; right: -110px; font-style: normal; } label em{ height:40px; position: absolute; left:0; top:1px; } label:hover em{ z-index: 1; } .item5:hover em,.item5 input:checked~em{ width: 40px; background: #f00; } .item4:hover em,.item4 input:checked~em{ width: 81px; background:#ffa800; } .item3:hover em,.item3 input:checked~em{ width: 122px; background: #e1e400; } .item2:hover em,.item2 input:checked~em{ width: 163px; background: #ace400; } .item1:hover em,.item1 input:checked~em{ width: 204px; background: #00e400; } </style> </head> <body> <div class="box"> <label class="item1"> <input type="radio" name="grid"> <span></span> <dfn>非常好</dfn> <em></em> </label> <label class="item2"> <input type="radio" name="grid"> <span></span> <dfn>很好</dfn> <em></em> </label> <label class="item3"> <input type="radio" name="grid"> <span></span> <dfn>一般</dfn> <em></em> </label> <label class="item4"> <input type="radio" name="grid"> <span></span> <dfn>较差</dfn> <em></em> </label> <label class="item5"> <input type="radio" name="grid"> <span></span> <dfn>很差</dfn> <em></em> </label> </div> </body> </html>
这是JS入门的一个小效果,相信大家也都见过,不必多说。
其实用到的技巧也不多,主要就是“+”、“~”这两个比较骚的选择器再配合单选按钮的checked伪类
相关文章推荐
- android的seekBar小技巧(评分星级的拖动效果)
- 自学前端的小伙伴看过来 jQuery五角星评分小效果
- 仿商业网站——商品评分效果实现【提高篇】
- JS实现仿新浪微博大厅和腾讯微博首页滚动效果_前端开发
- java-小技巧-001-Long序列化到前端js不支持
- 前端开发者都应知道的 jQuery 小技巧
- 前端程序员应该知道的 15 个 jQuery 小技巧
- js实现五星评分的效果
- 前端--手风琴效果
- 前端小技巧
- 前端开发者都应知道的 jQuery 小技巧
- web前端javaScript仿京东淘宝图片鼠标浮动图片上移效果
- 前端工程师-----一些ps小技巧
- css实现半颗星评分效果
- 五角星评分效果
- html+js+jquary完成的五星评分(评价效果demo)
- 前端开发者应该知道的 CSS 小技巧
- 前端同学常常会对一些交互效果质疑
- 前端效果——持续更新。。。