用css制作星級(jí)評(píng)分第2/3頁(yè)
第一個(gè)模型中忽視了半星級(jí)的情況和無(wú)初始的星級(jí),下來(lái)我們就是要解決這個(gè)問(wèn)題。
Step 1. 先看看效果|Check it in action
圖1
Step 2: The XHTML
<ul class="star-rating">
<li class="current-rating">Currently 3.5/5 Stars.</li>
<li><a href="#" title="1 star out of 5" class="one-star">1</a></li>
<li><a href="#" title="2 stars out of 5" class="two-stars">2</a></li>
<li><a href="#" title="3 stars out of 5" class="three-stars">3</a></li>
<li><a href="#" title="4 stars out of 5" class="four-stars">4</a></li>
<li><a href="#" title="5 stars out of 5" class="five-stars">5</a></li>
</ul>
和第一個(gè)模型的結(jié)構(gòu)相似,唯一不同的是:
<li class="current-rating">Currently 3.5/5 Stars.</li>
定義初始值
Step 3: The Star Image
我們制作一個(gè)有三個(gè)星的圖片,第一個(gè)星是空值,第二個(gè)是要選擇的值,第三個(gè)是真實(shí)的值。
圖2
Step 4: The CSS, the Magic
.star-rating li.current-rating{
background: url(star_rating.gif) left bottom;
position: absolute;
height: 30px;
display: block;
text-indent: -9000px;
z-index: 1;
}
他定義了初始值,為了避免繼承容器ul的相對(duì)定位,采用position: absolute;每個(gè)星的高度為height:30px;別的就是隱藏文本和定義對(duì)齊方式。
空值css
.star-rating{
…
background: url(star_rating.gif) top left repeat-x;
}
選擇值css
.star-rating li a:hover{
background: url(star_rating.gif) left center;
…
}
初始值當(dāng)然會(huì)隨著選擇變動(dòng),那么怎樣實(shí)現(xiàn)它的變化呢?
<li class="current-rating" style="width:105px;">Currently 3.5/5 Stars.</li>
看了這段代碼相信你就知道是什么原因了!那這個(gè)width是怎樣計(jì)算的呢?
Average Rating|平均值: 3.5
Each Star Width|每個(gè)星的寬度: 30px;
Set width to|將寬度設(shè)為: 3.5 * 30 = 105px
下面欣賞一下這個(gè)新模型吧
* Example 1: 150 x 30 star rating system
* Example 2: 125 x 25 star rating system
* Example 3: 25 x 125 vertical star rating system
- jQuery+PHP星級(jí)評(píng)分實(shí)現(xiàn)方法
- jQuery動(dòng)態(tài)星級(jí)評(píng)分效果實(shí)現(xiàn)方法
- jquery插件star-rating.js實(shí)現(xiàn)星級(jí)評(píng)分特效
- 使用jQuery實(shí)現(xiàn)星級(jí)評(píng)分代碼分享
- 基于jQuery的星級(jí)評(píng)分插件
- 原生JS實(shí)現(xiàn)-星級(jí)評(píng)分系統(tǒng)的簡(jiǎn)單實(shí)例
- JavaScript制作淘寶星級(jí)評(píng)分效果的思路
- JS實(shí)現(xiàn)帶提示的星級(jí)評(píng)分效果完整實(shí)例
- javascript 星級(jí)評(píng)分效果(手寫(xiě))
- jQuery Raty 一款不錯(cuò)的星級(jí)評(píng)分插件
相關(guān)文章
用css來(lái)控制圖片大小顯示的實(shí)現(xiàn)方法與代碼
用css來(lái)控制圖片大小顯示的實(shí)現(xiàn)方法與代碼...2007-03-03css也瘋狂! 用background 插入flash播放器
css也瘋狂! 用background 插入flash播放器...2007-01-01在解決ul居中問(wèn)題時(shí)想到的幾點(diǎn)
在解決ul居中問(wèn)題時(shí)想到的幾點(diǎn)...2007-09-09position:relative/absolute無(wú)法沖破的等級(jí)
position:relative/absolute無(wú)法沖破的等級(jí)...2007-03-03