2016-10-28 43 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请想想,并尝试自己之前,拇指下来任何答案 –