网站公告列表

没有公告

加入收藏
设为首页
联系站长
轻松学电脑>>网页制作>>其它教程>>用css制作星级评分
双击滚屏阅读

用css制作星级评分

原文:
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

[1] [2] [3] [4] [5] 下一页

 
  • 上一篇文章:

  • 下一篇文章:
  • 广告
    阅读top10
    普通文章[突破]在线编辑器任意…
    普通文章[JS]点出统计器
    普通文章[效果]JS折叠菜单
    普通文章javascript的函数
    普通文章怎么用javascript…
    普通文章百分百弹窗
    普通文章hta应用—代码统计工具
    普通文章小方框中浏览大图
    普通文章js版sliderBar(滑动条…
    普通文章JS代码格式化和语法着…
    普通文章好玩的样式—放大效果
    普通文章用css制作星级评分
    普通文章关于textarea的直观换…
    普通文章仿windows选项卡效果拾…
    查看用css制作星级评分全部内容
    本站提供:电脑教程 网页制作 Flash教程 PhotoShop教程等免费教程。
    Copyright © 2006-2008轻松学电脑All Rights Reserved