您好,登錄后才能下訂單哦!
這篇文章主要介紹“如何使用CSS繪制星級(jí)評(píng)分效果”,在日常操作中,相信很多人在如何使用CSS繪制星級(jí)評(píng)分效果問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”如何使用CSS繪制星級(jí)評(píng)分效果”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
先來看一下CSS繪制五角星的基本方法:
CSS Code復(fù)制內(nèi)容到剪貼板
#star-five {
margin: 50px 0;
position: relative;
display: block;
color: red;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-moz-transform: rotate(35deg);
-webkit-transform: rotate(35deg);
-ms-transform: rotate(35deg);
-o-transform: rotate(35deg);
}
#star-five:before {
border-bottom: 80px solid red;
border-left: 30px solid transparent;
border-right: 30px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -45px;
left: -65px;
display: block;
content: "";
-webkit-transform: rotate(-35deg);
-moz-transform: rotate(-35deg);
-ms-transform: rotate(-35deg);
-o-transform: rotate(-35deg);
}
#star-five:after {
position: absolute;
display: block;
color: red;
top: 3px;
left: -105px;
width: 0px;
height: 0px;
border-right: 100px solid transparent;
border-bottom: 70px solid red;
border-left: 100px solid transparent;
-webkit-transform: rotate(-70deg);
-moz-transform: rotate(-70deg);
-ms-transform: rotate(-70deg);
-o-transform: rotate(-70deg);
content: "";
}
有了這個(gè)基礎(chǔ),基本上星級(jí)評(píng)分的效果就容易實(shí)現(xiàn)了:
下圖是Demo中會(huì)用到的圖,可右鍵另存
HTML Code
XML/HTML Code復(fù)制內(nèi)容到剪貼板
<ul class="rating nostar">
<li class="one"><a href="#" title="1 Star">1</a>
</li>
<li class="two"><a href="#" title="2 Stars">2</a>
</li>
<li class="three"><a href="#" title="3 Stars">3</a>
</li>
<li class="four"><a href="#" title="4 Stars">4</a>
</li>
<li class="five"><a href="#" title="5 Stars">5</a>
</li>
</ul>
CSS Code
CSS Code復(fù)制內(nèi)容到剪貼板
.rating {
width: 124px;
height: 19px;
margin: 0 0 20px 0;
padding: 0;
list-style: none;
clear: both;
position: relative;
background: url(http://www.zjgsq.com/wp-content/uploads/2014/09/stars.png) no-repeat 0 0;
}
.nostar {
background-position: 0 0
}
.onestar {
background-position: 0 -19px
}
.twostar {
background-position: 0 -38px
}
.threestar {
background-position: 0 -57px
}
.fourstar {
background-position: 0 -76px
}
.fivestar {
background-position: 0 -95px
}
ul.rating li {
cursor: pointer;
float: left;
text-indent: -999em;
}
ul.rating li a {
position: absolute;
left: 0;
top: 0;
width: 25px;
height: 19px;
text-decoration: none;
z-index: 200;
}
ul.rating li.one a {
left: 0
}
ul.rating li.two a {
left: 25px;
}
ul.rating li.three a {
left: 50px;
}
ul.rating li.four a {
left: 75px;
}
ul.rating li.five a {
left: 100px;
}
ul.rating li a:hover {
z-index: 2;
width: 125px;
height: 19px;
overflow: hidden;
left: 0;
background: url(http://www.zjgsq.com/wp-content/uploads/2014/09/stars.png) no-repeat 0 0
}
ul.rating li.one a:hover {
background-position: 0 -19px;
}
ul.rating li.two a:hover {
background-position: 0 -38px;
}
ul.rating li.three a:hover {
background-position: 0 -57px
}
ul.rating li.four a:hover {
background-position: 0 -76px
}
ul.rating li.five a:hover {
background-position: 0 -95px
}
這樣就基本實(shí)現(xiàn)了鼠標(biāo)hover顯示對(duì)應(yīng)的星級(jí),后面再增加點(diǎn)JS來實(shí)現(xiàn)click效果就可以啦
到此,關(guān)于“如何使用CSS繪制星級(jí)評(píng)分效果”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。