2016-10-28 82 views
-1

我用這個例子來爲多段CSS>字體 - 真棒多星級

提供評級我的網頁

https://codepen.io/anon/pen/KgLomj

我的問題是,當我設置開始的第一組它會影響其他組;我只是想知道如何讓每個人都獨立工作。

<input type="radio" id="star5" name="rating" value="5" checked/> 
<label class = "full" for="star5" title="Awesome - 5 stars"></label> 

但是,當我將每個輸入設置爲「checked」時,它會影響其他星羣。

任何想法?

+0

請包括相關的代碼重現你的問題在你的問題,鏈接到外部演示是*獎金*,但不是必需的。在你的問題*中發佈相關的「* [MCVE] *」代碼是*要求;而缺乏這樣的結論是將問題作爲「題外話」來解決的理由。 –

+0

看看這個。 https://github.com/dreyescat/bootstrap-rating – usrNotFound

+0

@CannotFindSymbol我不想使用JavaScript,我需要它只是css – marvillous

回答

0

問題是您的輸入名稱對於所有這兩個組都是相同的。更改所有組設置的所有輸入名稱。

的HTML

<h1>Pure CSS Star Rating Widget 1</h1> 
<fieldset class="rating"> 
    <input type="radio" id="star5a" name="ratinga" value="5" checked/><label class = "full" for="star5a" title="Awesome - 5 stars"></label> 
    <input type="radio" id="star4halfa" name="ratinga" value="4 and a half" /><label class="half" for="star4halfa" title="Pretty good - 4.5 stars"></label> 
    <input type="radio" id="star4a" name="ratinga" value="4" /><label class = "full" for="star4a" title="Pretty good - 4 stars"></label> 
    <input type="radio" id="star3halfa" name="ratinga" value="3 and a half" /><label class="half" for="star3halfa" title="Meh - 3.5 stars"></label> 
    <input type="radio" id="star3a" name="ratinga" value="3" /><label class = "full" for="star3a" title="Meh - 3 stars"></label> 
    <input type="radio" id="star2halfa" name="ratinga" value="2 and a half" /><label class="half" for="star2halfa" title="Kinda bad - 2.5 stars"></label> 
    <input type="radio" id="star2a" name="ratinga" value="2" /><label class = "full" for="star2a" title="Kinda bad - 2 stars"></label> 
    <input type="radio" id="star1halfa" name="ratinga" value="1 and a half" /><label class="half" for="star1halfa" title="Meh - 1.5 stars"></label> 
    <input type="radio" id="star1a" name="ratinga" value="1" /><label class = "full" for="star1a" title="Sucks big time - 1 star"></label> 
    <input type="radio" id="starhalfa" name="ratinga" value="half" /><label class="half" for="starhalfa" title="Sucks big time - 0.5 stars"></label> 
</fieldset> 

<div> <br><br><br><div> 
<h1>Pure CSS Star Rating Widget 2</h1> 
<fieldset class="rating"> 
    <input type="radio" id="star5b" name="ratings" value="5" /><label class = "full" for="star5b" title="Awesome - 5 stars"></label> 
    <input type="radio" id="star4halfb" name="ratings" value="4 and a half" /><label class="half" for="star4halfb" title="Pretty good - 4.5 stars"></label> 
    <input type="radio" id="star4b" name="ratings" value="4" /><label class = "full" for="star4b" title="Pretty good - 4 stars"></label> 
    <input type="radio" id="star3halfb" name="ratings" value="3 and a half" /><label class="half" for="star3halfb" title="Meh - 3.5 stars"></label> 
    <input type="radio" id="star3b" name="ratings" value="3" checked/><label class = "full" for="star3b" title="Meh - 3 stars"></label> 
    <input type="radio" id="star2halfb" name="ratings" value="2 and a half" /><label class="half" for="star2halfb" title="Kinda bad - 2.5 stars"></label> 
    <input type="radio" id="star2b" name="ratings" value="2" /><label class = "full" for="star2b" title="Kinda bad - 2 stars"></label> 
    <input type="radio" id="star1halfb" name="ratings" value="1 and a half" /><label class="half" for="star1halfb" title="Meh - 1.5 stars"></label> 
    <input type="radio" id="star1b" name="ratings" value="1" /><label class = "full" for="star1b" title="Sucks big time - 1 star"></label> 
    <input type="radio" id="starhalfb" name="ratings" value="half" /><label class="half" for="starhalfb" title="Sucks big time - 0.5 stars"></label> 
</fieldset> 

的CSS

@import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css); 

fieldset, label { margin: 0; padding: 0; } 
body{ margin: 20px; } 
h1 { font-size: 1.5em; margin: 10px; } 

/****** Style Star Rating Widget *****/ 

.rating { 
    border: none; 
    float: left; 
} 

.rating > input { display: none; } 
.rating > label:before { 
    margin: 5px; 
    font-size: 1.25em; 
    font-family: FontAwesome; 
    display: inline-block; 
    content: "\f005"; 
} 

.rating > .half:before { 
    content: "\f089"; 
    position: absolute; 
} 

.rating > label { 
    color: #ddd; 
float: right; 
} 

/***** CSS Magic to Highlight Stars on Hover *****/ 

.rating > input:checked ~ label, /* show gold star when clicked */ 
.rating:not(:checked) > label:hover, /* hover current star */ 
.rating:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */ 

.rating > input:checked + label:hover, /* hover current star when changing rating */ 
.rating > input:checked ~ label:hover, 
.rating > label:hover ~ input:checked ~ label, /* lighten current selection */ 
.rating > input:checked ~ label:hover ~ label { color: #FFED85; } 
+0

你嘗試改變並看到輸出? –

+0

對不起,我不明白你最後的評論,請你給我舉個例子嗎? – marvillous

+0

@Reddy請想想,並嘗試自己之前,拇指下來任何答案 –