我試圖創建一個5星級系統,顯示您懸停的星星數量。用於星級評分系統的CSS
所以,有一個背景,它具有分的寬度,然後在它前面有具有5個不同的彩色星星的相同形狀的div,這個div默認的寬度爲0。
當一個人將光標懸停在寬度上時,通過適當調整寬度顯示第二個背景。
我不能得到這個工作,這是我的小提琴:http://jsfiddle.net/AAgU9/
我的HTML是:
<div style="position:relative">
<div class="stb"></div>
<div class="stf"></div>
<div class="sts st1"></div>
<div class="sts st2"></div>
<div class="sts st3"></div>
<div class="sts st4"></div>
<div class="sts st5"></div>
</div>
我的CSS是:
.stb{
background:red;
width:140px;
height:27px;
cursor:pointer}
.stf{
position:absolute;
width:0;
height:27px;
top:0;
left:0;
background:green 0 -26px;
cursor:pointer}
.sts{
position:absolute;
width:28px;
height:27px;
top:0;
cursor:pointer;
z-index:2}
.st1{left:0}
.st2{left:28px}
.st3{left:56px}
.st4{left:84px}
.st5{left:112px}
.st1:hover .stf{background:red}
.st2:hover .stf{width:56px}
.st3:hover .stf{width:84px}
.st4:hover .stf{width:112px}
.st5:hover .stf{width:140px}
我在做什麼錯?
.st5:懸停.STF將目標div.st5的後代div.stf,但stf實際上是st5的兄弟姐妹。 – Andrew
你的'.st1:hover .stf'等人......你沒有任何'.st1'的孩子,那些規則怎麼運作? – Ming
看看這個:http://css-tricks.com/examples/StarRating/ – Andrew