用css制作星级投票评分功能
作者:greengnn 来源:蓝色理想 发布时间:2008-01-08 21:12:00
标签:评分,星级,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>
这里只介绍静态的技术,PHP系统的应用请看,你也是自己加程序来尝试一下,还可以采用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;
}
到此,这个制作完成


猜你喜欢
- 这篇文章主要介绍了python自动化unittest yaml使用过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参
- 前言在学习python的过程中,我们会使用到各种各样的第三方库,但是如何pip有n种方法,如系统提示 如在terminal中pip
- 还记得以前在工作中,将爬来的其它网站的数据导到xml。但是会遇到一个问题:即网页会有ascII的控制字符。一开始以为是别人为了防止采集而加入
- 介绍毫无疑问,任何一个试图使用 CSS 的网页设计师和开发人员都会发现不同的浏览器要求不同的样式声明。这些烦恼归咎于各浏览器及其各版本不同程
- 我们都知道因为操作系统的不同,很多游戏区分为安卓和苹果两个版本。那么之前学会python模拟点击的小伙伴开始担心,如果手机是ios版本那还能
- 一、Go语言通道基础概念1.channel产生背景 线程之间进行通信的时候,会因为资源的争夺而产生竟态问
- 本文实例为大家分享了python3实现猜数字游戏的具体代码,供大家参考,具体内容如下需求目标:需求:猜数字游戏1: 开始游戏产生一个1~10
- 写在前面在用pd.read_csv读取数据集时,我有2个疑问?1是:写相对路径还是绝对路径。2是:相对路径,绝对路径怎么写。这篇文章就是解决
- 热词图很酷炫,也非常适合热点事件,抓住重点,以图文结合的方式表现出来,很有冲击力。下面这段代码是制作热词图的,用到了以下技术:jieba,把
- 本文实例讲述了Python基础之函数基本用法与进阶。分享给大家供大家参考,具体如下:目标函数参数和返回值的作用函数的返回值 进阶函数的参数
- 本文研究的主要内容是Python中装饰器相关学习总结,具体如下。装饰器(decorator)功能引入日志函数执行时间统计执行函数前预备处理执
- 在进行爬虫爬取淘宝商品信息时候,利用selenium来模拟浏览器进行爬取时遇到了这个问题:selenium.common.exception
- def ddns():"""用当前ip更新ddns"""headers = {&
- 这是一篇关于使用JScript RuntimeObject(MSDN)调试的文章。虽然这些例子中的大多数在其他浏览器中不能运行,但在IE 5
- 1、背景由于办公需要“每天定时推送某消息用来提醒群里面所有人”,于是决定用企业微信自带的机器人来实现此功能。具体方法我来一一讲述。2、企业微
- 直接看如下图解1、右击项目,查看提交历史2、选择要回滚的版本,点击回滚3、push回滚的内容:双击该回滚记录,弹出后,检查一下回滚的内容,没
- 1、集合相加a = {1,2,3}b = {3,4,5}print(type(a))print(a|b)2、queryset 符合条件的筛序
- 使用WebDriver在Chrome浏览器上进行测试时,需要从http://chromedriver.storage.googleapis.
- 写在前面这篇文章主要让大家明白多线程爬虫,因为go语言实现并发是很容易的。这次的服务端,是我们之前搭建的电子商城平台,所以我们不担心ip被封
- 今天好不容易闲下来半天,所以和大家分享一下我之前总结的一套Web UI 设计命名规范,也就是网站用户界面设计(俗称网页设计)命名规范。这套规