《
CSS制作星級評價(jià)的功能》文章地址:http://www.tfxk.com/wangyesheji/jianzhanjingyan/0302333022013.htm
CSS:
效果很簡單,可能現(xiàn)在您當(dāng)初頭腦里已經(jīng)有實(shí)現(xiàn)的思路了。下面先看一下咱們通常情形下的實(shí)現(xiàn)方式:
Code highlighting produced by Actipro CodeHighlighter (freeware) --><p>Javascript + CSS實(shí)現(xiàn)</p>
<ul ,
CSS初學(xué)者必知CSS技巧;class="jsstar">
<li title="一星"></li>
<li title="二星"></li>
<li title="三星"></li>
<li title="四星"></li>
<li title="五星"></li>
</ul>
--> [
網(wǎng)站建設(shè)之]CSS制造星級評估的功效
是不是跟上面的沒什么差別,可是又一想如果用戶禁掉了javascript豈不是效果很慘?
看看上面CSS的行號你是不是嚇了一跳,這么簡單的效果居然用了這么多代碼?在我看來不必JS就只能一個(gè)效果一個(gè)款式了,假如您還有更簡略更炫的后果請指教!
CSS:
這里是效果圖:
做一個(gè)星級評價(jià)的功能不是很難,然而要單純用CSS寫估量就有點(diǎn)難度了,先來個(gè)截圖:
代碼 Code highlighting produced by Actipro CodeHighlighter (freeware)> 1 /*CSS Star start*/
2 .star-rating
3 {
4 list-style: none;
5 margin: 0px;
6 padding: 0px;
7  ,
CSS創(chuàng)建圓角框; width: 100px;
8 height: 20px;
9 position: relative;
10 background: url(star_rating.gif) top left repeat-x;
11 }
12 .star-rating li
13  ,
CSS分內(nèi)部和外部兩種方式; {
14 padding: 0px;
15 margin: 0px;
16 float: left;
17 }
18 .star-rating li a
19 {
20 display: block;
21 width: 20px;
22 height: 20px;
23 text-decoration: none;
24 text-indent: -9000px;
25 z-index: 20;
26 position: absolute;
27 padding: 0px;
28 }
29 .star-rating li a:hover
30 {
31 background: url(star_rating.gif) left bottom;
32 z-index: 1;
33 left: 0px;
34 }
35 .star-rating a.one-star
36 {
37 left: 0px;
38 }
39 .star-rating a.one-star:hover
40 {
41 width: 20px;
42 }
43 .star-rating a.two-stars
44 {
45 left: 20px;
46 }
47 .star-rating a.two-stars:hover
48 {
49 width: 40px;
50 }
51 .star-rating a.three-stars:hover
52 {
53 width: 60px;
54 }
55 .star-rating a.three-stars
56 {
57 left: 40px;
58 }
59 .star-rating a.four-stars
60 {
61 left: 60px;
62 }
63 .star-rating a.four-stars:hover
64 {
65 width: 80px;
66 }
67 .star-rating a.five-stars
68 {
69 left: 80px;
70 }
71  ,
css兼容調(diào)試常見情況及相應(yīng)方法; .star-rating a.five-stars:hover
72  ,
CSS兼容要點(diǎn)總結(jié); {
73 width: 100px;
74
75 }
于是我們想到了用純CSS實(shí)現(xiàn),下面是代碼:
Tag:星級評價(jià) 星級評價(jià)
Code highlighting produced by Actipro CodeHighlighter (freeware)><ul class='star-rating'>
<li><a href='#' title='一星' class='one-star'>1</a></li>
<li><a href='#' title='二星' class='two-stars'>2</a></li>
<li><a href='#' title='三星' class='three-stars'>3</a></li>
<li><a href='#' title='四星' class='four-stars'>4</a></li>
<li><a href='#' title='五星' class='five-stars'>5</a></li>
</ul>
示例代碼下載
JS:(我用的是jquery)
Code highlighting produced by Actipro CodeHighlighter (freeware) --><script type="text/javascript" src="jquery-1.3.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 ,
CSS兼容性(IE和Firefox)技巧大全; $(".jsstar >li").hover(
function(){$(this).css({"background-position":"left bottom"}).prev().trigger("mouseover")},
function(){$(this).css({"background-position":"left top"}).prev().trigger("mouseout")})
.click(function(){alert($(this).attr("title"))});
});
</script>
代碼 Code highlighting produced by Actipro CodeHighlighter (freeware) --> .jsstar
{ list-style: none;
 ,
CSS兼容 用CSS代碼來判斷瀏覽器是Firefox、IE6、IE7的代碼; margin: 0px;
padding: 0px;
width: 100px;
height: 20px;
position: relative;
 ,
CSS入門教程:長度與單位;
}
.jsstar li
 ,
CSS入門教程:詳解border color;{
padding:0px;
margin: 0px;
float: left;
 ,
CSS入門教程:整數(shù)類型與實(shí)數(shù)類型;width:20px;
height:20px;
background:url(star_rating.gif) 0 0 no-repeat;
}
HTML:
HTML:
(責(zé)任編輯:網(wǎng)站建設(shè))
CSS制作星級評價(jià)的功能相關(guān)文章