2017-10-14 5 views
1

J'essaie de construire un système de notation simple en utilisant HTML et CSS. C'est une barre de notation très simple composée de 5 étoiles.Simple Rating Star CSS

fieldset, 
 
label { 
 
    margin: 0; 
 
    padding: 0; 
 
    margin-bottom: 20px; 
 
} 
 

 
.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; 
 
} 
 

 
.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; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/> 
 

 
<fieldset class="rating"> 
 

 
    <input type="radio" id="5star" name="rating" value="5" /> 
 
    <label class="full" for="star5" title="Excellent"></label> 
 

 
    <input type="radio" id="4halfstar" name="rating" value="4.5" /> 
 
    <label class="half" for="4halfstar" title="Good"></label> 
 

 
    <input type="radio" id="4star" name="rating" value="4" /> 
 
    <label class="full" for="4star" title="Pretty good"></label> 
 

 
    <input type="radio" id="3halfstar" name="rating" value="3.5" /> 
 
    <label class="half" for="3halfstar" title="Nice"></label> 
 

 
    <input type="radio" id="3star" name="rating" value="3" /> 
 
    <label class="full" for="3star" title="Ok"></label> 
 

 
    <input type="radio" id="2halfstar" name="rating" value="2.5" /> 
 
    <label class="half" for="2halfstar" title="Kinda bad"></label> 
 

 
    <input type="radio" id="2star" name="rating" value="2" /> 
 
    <label class="full" for="2star" title="Bad"></label> 
 

 
    <input type="radio" id="1halfstar" name="rating" value="1.5" /> 
 
    <label class="half" for="1halfstar" title="Meh"></label> 
 

 
    <input type="radio" id="1star" name="rating" value="1" /> 
 
    <label class="full" for="1star" title="Umm"></label> 
 

 
    <input type="radio" id="halfstar" name="rating" value="0.5" /> 
 
    <label class="half" for="halfstar" title="Worst"></label> 
 

 
</fieldset>

Le problème est que je ne peux sélectionner l'étoile jusqu'à 4,5 étoiles qui est la moitié de la 5ème étoile, ce que je veux est de sélectionner l'étoile 5 complet. J'ai inclus une image de la barre de notation ci-dessous. L'aide est vraiment appréciée.

Rating bar

+1

a 'id = "5star"', 'a l'étiquette pour = "star5" '... – CBroe

Répondre

1

Juste un typologique nécessaire pour changer star5-5star:

fieldset, 
 
label { 
 
    margin: 0; 
 
    padding: 0; 
 
    margin-bottom: 20px; 
 
} 
 

 
.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; 
 
} 
 

 
.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; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/> 
 

 
<fieldset class="rating"> 
 

 
    <input type="radio" id="5star" name="rating" value="5" /> 
 
    <label class="full" for="5star" title="Excellent"></label> 
 

 
    <input type="radio" id="4halfstar" name="rating" value="4.5" /> 
 
    <label class="half" for="4halfstar" title="Good"></label> 
 

 
    <input type="radio" id="4star" name="rating" value="4" /> 
 
    <label class="full" for="4star" title="Pretty good"></label> 
 

 
    <input type="radio" id="3halfstar" name="rating" value="3.5" /> 
 
    <label class="half" for="3halfstar" title="Nice"></label> 
 

 
    <input type="radio" id="3star" name="rating" value="3" /> 
 
    <label class="full" for="3star" title="Ok"></label> 
 

 
    <input type="radio" id="2halfstar" name="rating" value="2.5" /> 
 
    <label class="half" for="2halfstar" title="Kinda bad"></label> 
 

 
    <input type="radio" id="2star" name="rating" value="2" /> 
 
    <label class="full" for="2star" title="Bad"></label> 
 

 
    <input type="radio" id="1halfstar" name="rating" value="1.5" /> 
 
    <label class="half" for="1halfstar" title="Meh"></label> 
 

 
    <input type="radio" id="1star" name="rating" value="1" /> 
 
    <label class="full" for="1star" title="Umm"></label> 
 

 
    <input type="radio" id="halfstar" name="rating" value="0.5" /> 
 
    <label class="half" for="halfstar" title="Worst"></label> 
 

 
</fieldset>

entrée
+0

Yup! Cela résout, hahah :) – CodeX