您的位置: 首页 > 技术文档 > 网页制作 > 用css制作星级评分
好玩的样式—放大效果 回到列表 用javascript实现Base64编码
 用css制作星级评分

作者:greengnn 时间: 2006-06-18 文档类型:翻译 来自:蓝色理想

第 1 页 用css制作星级评分 [1]
第 2 页 用css制作星级评分 [2]
第 3 页 用css制作星级评分 [3]

原文:
Creating a Star Rater using CSS

链接:
http://komodomedia.com/blog/index.php/2005/08/24/creating-a-star-rater-using-css/

版权:
版权归原作者所有,翻译文档版权归本人|greengnn,和blueidea。

先看看效果

Step 1: XHTML

 <ul class="star-rating">  
    <li><a href="#" title="Rate this 1 star out of 5" class="one-star">1</a></li>   
    <li><a href="#" title="Rate this 2 stars out of 5" class="two-stars">2</a></li>  
    <li><a href="#" title="Rate this 3 stars out of 5" class="three-stars">3</a></li>  
    <li><a href="#" title="Rate this 4 stars out of 5" class="four-stars">4</a></li> 
    <li><a href="#" title="Rate this 5 stars out of 5" class="five-stars">5</a></li>
 </ul>

这里只介绍静态的技术,随后会给出系统的应用,你也是自己加程序来尝试一下,还可以采用ajax来做出绚丽的效果

Step 2:图像|Graphics

为了节省您的空间和宽带,我们采用gif图,这个图片就是打分的按钮。


Step 3:CSS

    .star-rating{
    list-style: none; /* turn off the default list image bullets*/
    margin: 3px; /*I wan’t some space around this thing*/
    padding: 0px; /* I’m anal. I’m pretty sure OL’s have a default padding of 0px, but we’ll set it to 0px just to be safe*/
    width: 100px; /*This list is 5 stars, each star is 20px, therefore it should be 5 x 20px = 100px wide*/
    height: 20px; /* The height of each star is 20px. Since this is a horizontal list, we will set the list height to the height of the star.*/
    position: relative; /*Very important. We will be using absolute positioning later. We want to use relatively-absolute positioning.*/
    background: url(star_rating.gif) top left repeat-x; /* By repeating this image horizontally, the list will appear to have five stars.*/
    }

根据代码我们知道:
去掉了ul的margin和padding以及list-style,定义了高20px宽100px的一个区块

下来时按钮元素的制作,下面是css

    .star-rating li{
    padding:0px; /* no padding at all*/
    margin:0px; /* no margin at all*/
    /*\*/ /*Backslash hack, this causes IE5 Mac NOT to see this rule*/
    float: left; /* for any other browser, we are going to float left, this makes a horizontal list*/
    /* */ /* end the IE5 Backslash hack*/
    }

这段代码让li实现横向排放,并解决IE5 MAC bug

继承上面的按钮元素样式,再定义鼠标动作,下面是css

   .star-rating li a{
    display:block; /* we want a block item, so that we can mess with its height and width*/
    width:20px; /* easy stuff, we want the width to be the same as the star width*/
    height: 20px; /* same as the width*/
    text-decoration: none; /* remove the underline from the link*/
    text-indent: -9000px; /* indent the text off the screen using a [url=http://www.mezzoblue.com/tests/revised-image-replacement/]image-replacement technique[/url], we dont want to see the text anymore.*/
    z-index: 20; /*we’ll come back to this*/
    position: absolute; /*we can now control the exact x and y coordinates of each star, relative to the parent UL*/
    padding: 0px; /*once again, we don’t need any padding*/
   background-image:none; /* we will not show the star*/
   }
  
  13. .star-rating li a:hover{
  14. background: url(star_rating.gif) left bottom; /*this is where the magic is*/
  15. z-index: 1; /*move this star to the bottom of the z-index stack*/
  16. left: 0px; /*move this star all the way to the left, aligned with the side of the UL parent item*/
  17. }

下来我们要考虑怎样才能显示不同的星级,三星?四星?原理是什么,我们继续将背景图片横向重复显示,然后定义a和a:hover的宽度来区分选择的星级。

下面是css

   .star-rating a.one-star{
    left: 0px;
    }  
   .star-rating a.one-star:hover{
    width:20px;
    }
   .star-rating a.two-stars{
    left:20px;
   }
   .star-rating a.two-stars:hover{
   width: 40px;
   }
   .star-rating a.three-stars{
   left: 40px;
   }
   .star-rating a.three-stars:hover{
   width: 60px;
   }
   .star-rating a.four-stars{
   left: 60px;
   }
   .star-rating a.four-stars:hover{
   width: 80px;
   }
   .star-rating a.five-stars{
   left: 80px;
   }
   .star-rating a.five-stars:hover{
   width: 100px;
   }

到此,这个制作完成

出处:蓝色理想
责任编辑:moby

上一页 下一页 用css制作星级评分 [2]

◎进入论坛网页制作网站综合版块参加讨论

相关文章 更多相关链接
好玩的样式—放大效果
斜体样式的导航条
css静态滤镜 + A:Hover
CSS超级技巧大放送合集
CSS锦囊
作者文章 更多作者文章
条件注释理论及实践
css元素定位
css之自动换行
CSS Image Maps—图像地图
用css制作表单并体验亲和力
关键字搜索 常规搜索 推荐文档
热门搜索:CSS Fireworks 设计比赛 网页制作 web标准 用户体验 UE photoshop Dreamweaver Studio8 Flash 手绘 CG
站点最新 站点最新列表
周大福“敬•自然”设计大赛开启
国际体验设计大会7月将在京举行
中国国防科技信息中心标志征集
云计算如何让安全问题可控
云计算是多数企业唯一拥抱互联网的机会
阿里行云
云手机年终巨献,送礼标配299起
阿里巴巴CTO王坚的"云和互联网观"
1499元买真八核 云OS双蛋大促
首届COCO桌面手机主题设计大赛
栏目最新 栏目最新列表
浅谈JavaScript编程语言的编码规范
如何在illustrator中绘制台历
Ps简单绘制一个可爱的铅笔图标
数据同步算法研究
用ps作简单的作品展示页面
CSS定位机制之一:普通流
25个最佳最闪亮的Eclipse开发项目
Illustrator中制作针线缝制文字效果
Photoshop制作印刷凹凸字体
VS2010中创建自定义SQL Rule
>> 分页 首页 前页 后页 尾页 页次:1/31个记录/页 转到 页 共3个记录

蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。

转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们联系,我们将立即删除修改。

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误  
专业书推荐 更多内容
网站可用性测试及优化指南
《写给大家看的色彩书1》
《跟我去香港》
众妙之门—网站UI 设计之道
《Flex 4.0 RIA开发宝典》
《赢在设计》
犀利开发—jQuery内核详解与实践
作品集 更多内容

杂⑦杂⑧ Gold NORMANA V2