用css制作星级评分第1/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;
   }

到此,这个制作完成

当前1/3页 123下一页阅读全文

时间: 2024-09-15 17:40:42

用css制作星级评分第1/3页_经验交流的相关文章

纯CSS制作的新闻网站中的文章列表_经验交流

应用CSS制作的新闻网站中的文章列表:ul是html中的无序列表,li是列表中的列表项.如果没有CSS定义它的外观,它默认是显示成一列列表,并且它会存在项目符号(比如方块或实心的黑点)的列表内容.CSS网页布局中,除了新闻列表.链接运行ul.li制作以外,我们通常将菜单也用ul.li来实现.  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtm

非常漂亮的Div+CSS布局入门教程第1/5页_经验交流

在网页制作中,有许多的术语,例如:CSS.HTML.DHTML.XHTML等等.在下面的文章中我们将会用到一些有关于HTML的基本知识,而在你学习这篇入门教程之前,请确定你已经具有了一定的HTML基础.下面我们就开始一步一步使用DIV+CSS进行网页布局设计吧. 所有的设计第一步就是构思,构思好了,一般来说还需要用PhotoShop或FireWorks(以下简称PS或FW)等图片处理软件将需要制作的界面布局简单的构画出来,以下是我构思好的界面布局图. 下面,我们需要根据构思图来规划一下页面的布局

学习WEB标准总结的一些CSS/XHTML知识小结第1/3页_经验交流

1.很多兼容性问题,是因为不同标签在不同浏览器下有着不同的 padding margin默认值.所以可以事先定义 复制代码 代码如下: * { padding:0; margin:0;} 或者 复制代码 代码如下: ul,li,h1,h2,h3,h4,h5,h6,p,table,td,div,img,hr,dd,dt,span,a,dt,dd,ol{margin:0;padding:0;font-size:12px;} 2.关于布局,可以看dreamweaver cs3里的模板怎么写的,它的写法

非常漂亮的css星级效果总结第1/2页_经验交流

用纯css打造星级评分效果正在被越来越多地应用在网络RIA中,结合ajax等技术,可以渲染出很出色的视觉效果和很棒的用户体验,在这篇文章开始之前,大家可以先去cssheaven感受一下. 最近由于项目需要,我在网上找了很多css星级评分的例子和说明,但是发现大多数都是翻译国外的文章,而且解释得并不是非常清楚,所以我决定自己来做一个总结,也希望能够给大家一些帮助. 首先用中文写一下这个效果的算法: 1. 使用背景图片的位置切换来获得星级效果: 2. 整个效果最关键的地方就是"三层理论",

div+CSS网页布局的意义与副作用原因小结第1/2页_经验交流

如今大部分网站仍然采用表格嵌套内容的方式来制作网站,虽然此方法对于我们来说比较熟悉.比较上手:但是,它却阻碍了一种更好的.更有亲和力的.更灵活的,而且功能更强大的网站设计方法--DIV+CSS. CSS网页布局的意义体现在如下方面: 一.使页面载入得更快 由于将大部分页面代码写在了CSS当中,使得页面体积容量变得更小.相对于表格嵌套的方式,DIV+CSS将页面独立成更多的区域,在打开页面的时候,逐层加载.而不像表格嵌套那样将整个页面圈在一个大表格里,使得加载速度很慢. 二.降低流量费用 页面体积

用css制作星级评分

css 原文:Creating a Star Rater using CSS链接:http://komodomedia.com/blog/index.php/2005/08/24/creating-a-star-rater-using-css/版权:版权归原作者所有,翻译文档版权归本人|greengnn,转载请注明出处Step 1: XHTML  <ul class="star-rating">        <li><a href="#&quo

提高CSS文件可维护性的五种方法总结_经验交流

1.分解你的样式  对于小项目,在写代码之前,按页面结构或页面内容将代码分为几块并给予注释.例如,可以分别将 全局样式.布局.字体样式.表单.评论和其他分为几个不同的块来继续工作.  而对于较大的工程,这样显然不会有什么效果.此时,就需要将样式分解到几个不同的样式表文件.下面的master stylesheet 就是这一方法的例子,它的工作主要是导入其他样式文件.使用这一方法不仅能优化样式结构,而且有利于减少一些不必要的服务器请求.而分解文件的方法就有许多种,master stylesheet 

CSS标签切换代码实例教程 比较漂亮_经验交流

我们的设计越来越追求一种简洁的风格,希望在有限的空间内展示更多的内容.与此同时我们发现一些问题,内容的简单排列总使页面很长.滚屏很多才能将显示的内容布局完毕.YAHOO与网易率先应用了标签切换的布局方式,打破了常规布局的局限性,在相同尺寸的区域内,可以放置更多的内容.我们只需要点击不同的选项卡或链接就能展开内容,这并不需要打开新的网页,只是在同一页内完成. 一.标签切换总体的实现思路: 实现这种标签切换的布局有多种方式,也流传着各种不同的代码,我们应用DIV CSS进行布局,首先来整理一下思路,

css文本框与按钮美化效果代码_经验交流

一.先看看在网页中经常出现的按钮与文本框的本来面目吧! 对照上图,我们怎么样才能改变文本框与按钮的模样呢?那在下面我为大家提供两种文本框与按钮样式作为例子参考,第一种是文本框与按钮无立体感,只是有线 条颜色与填充颜色的,这种效果大家可能在很多网站上都看见过,给人一种特别的感觉,很不错的,第二种效果就比较特殊了,是将文本框做成一种类似于下划线的 效果并且是彩色的,同时按钮的背景色也不再是灰色,而是彩色的,可以说这是一种非常酷的效果,好了,下面我就来说说这两种效果实现的详细操作步骤吧. 二.无立体效