« 普及一下域名注册知识(新手必读)asp用ADO可以打开EXCEL文件 »

CSS 动态显示等级选择器

本文创意来自Komodo Media,使用偏移替换背景图已经不是新鲜用法,不过能把技巧和应用结合的如此完美倒很少见。

本方案就是采用纯CSS实现人工选择评级时,能动态的显示出选择状态,并且支持链接。

效果演示:http://www.rexsong.com/blog/attachme...s_selector.htm

结构代码简单的不能再简单:
HTML 代码:
<ul class="star"> <li><a href="#" title="Rate this 1 star out of 5" class="one-star">&nbsp;</a></li> <li><a href="#" title="Rate this 2 stars out of 5" class="two-stars">&nbsp;</a></li> <li><a href="#" title="Rate this 3 stars out of 5" class="three-stars">&nbsp;</a></li> <li><a href="#" title="Rate this 4 stars out of 5" class="four-stars">&nbsp;</a></li> <li><a href="#" title="Rate this 5 stars out of 5" class="five-stars">&nbsp;</a></li> </ul>

所有CSS技巧都应用在了这张20*40PX的图片上:



定义基本容器,宽度刚好够平铺5个图片,高度只显示图片上半部分未选中状态:
HTML 代码:
.star { list-style:none; position:relative; margin:0; padding:0; width:100px; height:20px;background:url(13_010531_star_rating.gif) top left repeat-x;}

定义每个单元,及触发显示图片下半部分选中状态,注意要采用绝对定位方法:
HTML 代码:
.star li a { display:block; width:20px; height:20px; z-index:2; position:absolute; padding:0;}.star li a:hover { background:url(13_010531_star_rating.gif) bottom left; z-index:1; left:0;}

最后就是分别定义每个单元格的偏移量,和链接触发可控制宽度:
HTML 代码:
.star a.one-star { left:0;}.star a.one-star:hover { width:20px;}.star a.two-stars { left:20px;}.star a.two-stars:hover { width:40px;}.star a.three-stars { left:40px;}.star a.three-stars:hover { width:60px;}.star a.four-stars { left:60px;}.star a.four-stars:hover { width:80px;}.star a.five-stars { left:80px;}.star a.five-stars:hover { width:100px;}

IE6.0和FF1.5环境下测试成功
原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。