I am using this example to provide rating in my page for multi-sections
https://codepen.io/anon/pen/KgLomj
My problem is that when I set the first group of start it affects other groups; I just want to know how to made each one works independently.
<input type="radio" id="star5" name="rating" value="5" checked/>
<label class = "full" for="star5" title="Awesome - 5 stars"></label>
But currently when I set each input to "checked" it affects other groups of stars.
Any ideas?
The problem is your input name is same for all both group. change all input name for all group set.
the 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>
the 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; }
Related
I have tried to get font awesome to work in my css file but nothing is working. Do i need to link a certain website to my html for the css "content" to work?
here is a code pen with the html and css.
https://codepen.io/anon/pen/XwbxbG
<fieldset class="rating">
<input type="radio" id="star5" name="rating" value="5" /><label class = "full" for="star5" title="5 stars"></label>
<input type="radio" id="star4half" name="rating" value="4.5" /><label class="half" for="star4half" title="4.5 stars"></label>
<input type="radio" id="star4" name="rating" value="4" /><label class = "full" for="star4" title="4 stars"></label>
<input type="radio" id="star3half" name="rating" value="3.5" /><label class="half" for="star3half" title="3.5 stars"></label>
<input type="radio" id="star3" name="rating" value="3" /><label class = "full" for="star3" title="Meh - 3 stars"></label>
<input type="radio" id="star2half" name="rating" value="2.5" /><label class="half" for="star2half" title="2.5 stars"></label>
<input type="radio" id="star2" name="rating" value="2" /><label class = "full" for="star2" title="2 stars"></label>
<input type="radio" id="star1half" name="rating" value="1.5" /><label class="half" for="star1half" title="1.5 stars"></label>
<input type="radio" id="star1" name="rating" value="1" /><label class = "full" for="star1" title="Sucks big time - 1 star"></label>
<input type="radio" id="starhalf" name="rating" value=".5" /><label class="half" for="starhalf" title="0.5 stars"></label>
</fieldset>
fieldset, label { margin: 0; padding: 0; }
.rating {
border: none;
float: left;
}
.rating > input { display: none; }
.rating > label:before {
margin: 5px;
font-size: 1.25em;
font-family: "Font Awesome 5 Free";
font-weight: 900;
display: inline-block;
content: "\f005";
}
.rating > .half:before {
font-family: "Font Awesome 5 Free";
font-weight: 900;
content: "\f089";
position: absolute;
}
.rating > label {
color: #ddd;
float: right;
}
.rating > input:checked ~ label,
.rating:not(:checked) > label:hover,
.rating:not(:checked) > label:hover ~ label { color: #FFD700; }
.rating > input:checked + label:hover,
.rating > input:checked ~ label:hover,
.rating > label:hover ~ input:checked ~ label,
.rating > input:checked ~ label:hover ~ label { color: #FFED85; }
}
I have two sets of checkboxes, which act as a star rating system. One of the star ratings is disabled (by using the disabled attribute on the checkboxes), while the other one isnt.
When the user hovers over stars in the star rating system, they change colour to yellow. However if the star rating system is disabled, I do not want them to change colour when covered. I have tried to do this by using :not([disabled]) in the checkbox hover event in the CSS, but the stars still change colour on hover.
.rating,
.rating label {
margin: 0;
padding: 0;
margin-left: auto;
}
.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):not([disabled]) label:hover,
/* hover current star */
.rating:not(:checked) label:hover~label {
color: #FFD700;
}
/* 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" />
<p>This star rating system should not change colour on hover as the checkboxes are disabled</p>
<fieldset class="rating" id="93">
<input type="checkbox" id="5star_1" name="rating" value="5" disabled/>
<label class="full" for="5star_1" title="Excellent"></label>
<input type="checkbox" id="4halfstar_1" name="rating" value="4.5" disabled/>
<label class="half" for="4halfstar_1" title="Good"></label>
<input type="checkbox" id="4star_1" name="rating" value="4" disabled/>
<label class="full" for="4star_1" title="Pretty good"></label>
<input type="checkbox" id="3halfstar_1" name="rating" value="3.5" disabled/>
<label class="half" for="3halfstar_1" title="Nice"></label>
<input type="checkbox" id="3star_1" name="rating" value="3" disabled/>
<label class="full" for="3star_1" title="Ok"></label>
<input type="checkbox" id="2halfstar_1" name="rating" value="2.5" disabled/>
<label class="half" for="2halfstar_1" title="Kinda bad"></label>
<input type="checkbox" id="2star_1" name="rating" value="2" disabled/>
<label class="full" for="2star_1" title="Bad"></label>
<input type="checkbox" id="1halfstar_1" name="rating" value="1.5" disabled/>
<label class="half" for="1halfstar_1" title="Meh"></label>
<input type="checkbox" id="1star_1" name="rating" value="1" disabled/>
<label class="full" for="1star_1" title="Umm"></label>
<input type="checkbox" id="halfstar_1" name="rating" value="0.5" disabled/>
<label class="half" for="halfstar_1" title="Worst"></label>
</fieldset>
<br><br>
<p>This one does what it is supposed to (change its colour on hover)</p>
<fieldset class="rating" id="23">
<input type="checkbox" id="5star" name="rating" value="5" />
<label class="full" for="5star" title="Excellent"></label>
<input type="checkbox" id="4halfstar" name="rating" value="4.5" />
<label class="half" for="4halfstar" title="Good"></label>
<input type="checkbox" id="4star" name="rating" value="4" />
<label class="full" for="4star" title="Pretty good"></label>
<input type="checkbox" id="3halfstar" name="rating" value="3.5" />
<label class="half" for="3halfstar" title="Nice"></label>
<input type="checkbox" id="3star" name="rating" value="3" />
<label class="full" for="3star" title="Ok"></label>
<input type="checkbox" id="2halfstar" name="rating" value="2.5" />
<label class="half" for="2halfstar" title="Kinda bad"></label>
<input type="checkbox" id="2star" name="rating" value="2" />
<label class="full" for="2star" title="Bad"></label>
<input type="checkbox" id="1halfstar" name="rating" value="1.5" />
<label class="half" for="1halfstar" title="Meh"></label>
<input type="checkbox" id="1star" name="rating" value="1" />
<label class="full" for="1star" title="Umm"></label>
<input type="checkbox" id="halfstar" name="rating" value="0.5" />
<label class="half" for="halfstar" title="Worst"></label>
</fieldset>
Here is what it looks like in the developer tools with the hover state being forced on:
You are asking CSS to check if the container class has the disabled attribute (or not). You need to ask it if the input within the class has this attribute
something like:
.rating input:checked~label,
.rating input:not(:checked):not(:disabled) + label:hover,
.rating input:not(:checked):not(:disabled) + label:hover~label {
color: #FFD700;
}
Note:
You may do well to remove the first and third rules as well, and simply have the second rule apply.
Snippet:
.rating,
.rating label {
margin: 0;
padding: 0;
margin-left: auto;
}
.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,
.rating input:not(:checked):not(:disabled) + label:hover,
.rating input:not(:checked):not(:disabled) + label:hover~label {
color: #FFD700;
}
.rating input:checked~label:hover,
.rating label:hover~input:checked~label,
.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" />
<p>This star rating system should not change colour on hover as the checkboxes are disabled</p>
<fieldset class="rating" id="93">
<input type="checkbox" id="5star_1" name="rating" value="5" disabled/>
<label class="full" for="5star_1" title="Excellent"></label>
<input type="checkbox" id="4halfstar_1" name="rating" value="4.5" disabled/>
<label class="half" for="4halfstar_1" title="Good"></label>
<input type="checkbox" id="4star_1" name="rating" value="4" disabled/>
<label class="full" for="4star_1" title="Pretty good"></label>
<input type="checkbox" id="3halfstar_1" name="rating" value="3.5" disabled/>
<label class="half" for="3halfstar_1" title="Nice"></label>
<input type="checkbox" id="3star_1" name="rating" value="3" disabled/>
<label class="full" for="3star_1" title="Ok"></label>
<input type="checkbox" id="2halfstar_1" name="rating" value="2.5" disabled/>
<label class="half" for="2halfstar_1" title="Kinda bad"></label>
<input type="checkbox" id="2star_1" name="rating" value="2" disabled/>
<label class="full" for="2star_1" title="Bad"></label>
<input type="checkbox" id="1halfstar_1" name="rating" value="1.5" disabled/>
<label class="half" for="1halfstar_1" title="Meh"></label>
<input type="checkbox" id="1star_1" name="rating" value="1" disabled/>
<label class="full" for="1star_1" title="Umm"></label>
<input type="checkbox" id="halfstar_1" name="rating" value="0.5" disabled/>
<label class="half" for="halfstar_1" title="Worst"></label>
</fieldset>
<br><br>
<p>This one does what it is supposed to (change its colour on hover)</p>
<fieldset class="rating" id="23">
<input type="checkbox" id="5star" name="rating" value="5" />
<label class="full" for="5star" title="Excellent"></label>
<input type="checkbox" id="4halfstar" name="rating" value="4.5" />
<label class="half" for="4halfstar" title="Good"></label>
<input type="checkbox" id="4star" name="rating" value="4" />
<label class="full" for="4star" title="Pretty good"></label>
<input type="checkbox" id="3halfstar" name="rating" value="3.5" />
<label class="half" for="3halfstar" title="Nice"></label>
<input type="checkbox" id="3star" name="rating" value="3" />
<label class="full" for="3star" title="Ok"></label>
<input type="checkbox" id="2halfstar" name="rating" value="2.5" />
<label class="half" for="2halfstar" title="Kinda bad"></label>
<input type="checkbox" id="2star" name="rating" value="2" />
<label class="full" for="2star" title="Bad"></label>
<input type="checkbox" id="1halfstar" name="rating" value="1.5" />
<label class="half" for="1halfstar" title="Meh"></label>
<input type="checkbox" id="1star" name="rating" value="1" />
<label class="full" for="1star" title="Umm"></label>
<input type="checkbox" id="halfstar" name="rating" value="0.5" />
<label class="half" for="halfstar" title="Worst"></label>
</fieldset>
I have two star rating systems using radio buttons. When the user clicks the star, that star and all the stars behind it are supposed to turn yellow. You can see this in the comments in my CSS code (such as /* show gold star when clicked */).
I believe it has something to do with with the ::before element which appears maybe? But I'm not totally sure on this:
.rating {
border: none;
float: left;
}
.rating {
margin: 0;
padding: 0;
}
.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">
<label class="full" title="Excellent">
<input type="radio" name="rating" value="5" />
</label>
<label class="half" title="Good">
<input type="radio" name="rating" value="4.5" />
</label>
<label class="full" title="Pretty Good">
<input type="radio" name="rating" value="4" />
</label>
<label class="half" title="Nice">
<input type="radio" name="rating" value="3.5" />
</label>
<label class="full" title="Ok">
<input type="radio" name="rating" value="3" />
</label>
<label class="half" title="Kinda Bad">
<input type="radio" name="rating" value="2.5" />
</label>
<label class="full" title="Bad">
<input type="radio" name="rating" value="2" />
</label>
<label class="half" title="Meh">
<input type="radio" name="rating" value="1.5" />
</label>
<label class="full" title="Umm">
<input type="radio" name="rating" value="1" />
</label>
<label class="half" title="Worst">
<input type="radio" name="rating" value="0.5" />
</label>
</fieldset>
<br><br>
<fieldset class="rating">
<label class="full" title="Excellent">
<input type="radio" name="rating" value="5" />
</label>
<label class="half" title="Good">
<input type="radio" name="rating" value="4.5" />
</label>
<label class="full" title="Pretty Good">
<input type="radio" name="rating" value="4" />
</label>
<label class="half" title="Nice">
<input type="radio" name="rating" value="3.5" />
</label>
<label class="full" title="Ok">
<input type="radio" name="rating" value="3" />
</label>
<label class="half" title="Kinda Bad">
<input type="radio" name="rating" value="2.5" />
</label>
<label class="full" title="Bad">
<input type="radio" name="rating" value="2" />
</label>
<label class="half" title="Meh">
<input type="radio" name="rating" value="1.5" />
</label>
<label class="full" title="Umm">
<input type="radio" name="rating" value="1" />
</label>
<label class="half" title="Worst">
<input type="radio" name="rating" value="0.5" />
</label>
</fieldset>
As mentioned above, this is achievable in pure CSS, but it does require adding IDs and for attributes and restructuring the HTML a little to make the labels and radio buttons siblings, like so:
$(document).on('click', 'fieldset label', function () {
var that = this;
setTimeout(function() {
console.log('hidden val=',$(that).parent().find("input[type='hidden']").val());
console.log('checked val=',$(that).parent().find("input[type='radio']:checked").val());
},1);
});
.rating {
border: none;
float: left;
}
.rating {
margin: 0;
padding: 0;
}
.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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" />
<fieldset class="rating">
<input type="hidden" value="1">
<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>
<br><br>
<fieldset class="rating">
<input type="hidden" value="2">
<input type="radio" id="5star2" name="rating2" value="5" />
<label class="full" for="5star2" title="Excellent"></label>
<input type="radio" id="4halfstar2" name="rating2" value="4.5" />
<label class="half" for="4halfstar2" title="Good"></label>
<input type="radio" id="4star2" name="rating2" value="4" />
<label class="full" for="4star2" title="Pretty good"></label>
<input type="radio" id="3halfstar2" name="rating2" value="3.5" />
<label class="half" for="3halfstar2" title="Nice"></label>
<input type="radio" id="3star2" name="rating2" value="3" />
<label class="full" for="3star2" title="Ok"></label>
<input type="radio" id="2halfstar2" name="rating2" value="2.5" />
<label class="half" for="2halfstar2" title="Kinda bad"></label>
<input type="radio" id="2star2" name="rating2" value="2" />
<label class="full" for="2star2" title="Bad"></label>
<input type="radio" id="1halfstar2" name="rating2" value="1.5" />
<label class="half" for="1halfstar2" title="Meh"></label>
<input type="radio" id="1star2" name="rating2" value="1" />
<label class="full" for="1star2" title="Umm"></label>
<input type="radio" id="halfstar2" name="rating2" value="0.5" />
<label class="half" for="halfstar2" title="Worst"></label>
</fieldset>
This question already has answers here:
star rating html, css
(2 answers)
Closed 2 years ago.
so I have these radio buttons that form a star-rating component in reactjs, when I hover over the stars they paint in yellow but when I click in one of them and hover out of the stars the color doesn't stay and the gray color come back in all of them.
Here is the js file:
render(){
return (
<div className="star-rating">
<input id="star-5" type="radio" name="rating" value="star-5"></input>
<label for="star-5" title="5 stars">
<i className="active fa fa-star" aria-hidden="true"></i>
</label>
<input id="star-4" type="radio" name="rating" value="star-4"></input>
<label for="star-4" title="4 stars">
<i className="active fa fa-star" aria-hidden="true"></i>
</label>
<input id="star-3" type="radio" name="rating" value="star-3"></input>
<label for="star-3" title="3 stars">
<i className="active fa fa-star" aria-hidden="true"></i>
</label>
<input id="star-2" type="radio" name="rating" value="star-2"></input>
<label for="star-2" title="2 stars">
<i className="active fa fa-star" aria-hidden="true"></i>
</label>
<input id="star-1" type="radio" name="rating" value="star-1"></input>
<label for="star-1" title="1 star">
<i className="active fa fa-star" aria-hidden="true"></i>
</label>
</div>
);
}
and the css:
.star-rating {
direction: rtl;
display: inline-block;
padding: 20px
}
.star-rating input[type=radio] {
display: none
}
.star-rating label {
color: #bbb;
font-size: 50px;
padding: 0;
cursor: pointer;
}
.star-rating label:hover,
.star-rating label:hover ~ label,
.star-rating input[type=radio]:checked ~ label {
color: #f2b600
}
Any help?
try this from James Barnett
#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; }
<fieldset class="rating">
<input type="radio" id="star5" name="rating" value="5" /><label class = "full" for="star5" title="Awesome - 5 stars"></label>
<input type="radio" id="star4half" name="rating" value="4 and a half" /><label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
<input type="radio" id="star4" name="rating" value="4" /><label class = "full" for="star4" title="Pretty good - 4 stars"></label>
<input type="radio" id="star3half" name="rating" value="3 and a half" /><label class="half" for="star3half" title="Meh - 3.5 stars"></label>
<input type="radio" id="star3" name="rating" value="3" /><label class = "full" for="star3" title="Meh - 3 stars"></label>
<input type="radio" id="star2half" name="rating" value="2 and a half" /><label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
<input type="radio" id="star2" name="rating" value="2" /><label class = "full" for="star2" title="Kinda bad - 2 stars"></label>
<input type="radio" id="star1half" name="rating" value="1 and a half" /><label class="half" for="star1half" title="Meh - 1.5 stars"></label>
<input type="radio" id="star1" name="rating" value="1" /><label class = "full" for="star1" title="Sucks big time - 1 star"></label>
<input type="radio" id="starhalf" name="rating" value="half" /><label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label>
</fieldset>
I have a star system made with html and css only.
My issue is that when I change the rating of the second system the first one changes too. I tried to use different class names but apparently I am missing something. Any suggestions?
HTML
<div style="padding-top:20px;" class="row">
<div style="border-right: solid #4a98b5; width:290px;" class="col-
md-4"><p>Product Matches description</p></div>
<div style="font-size:20px;color:#FFD700" class="col-md-4">
<fieldset class="rating1">
<input type="radio" id="star5" name="rating1" value="5" /><label class = "full" for="star5" ></label>
<input type="radio" id="star4half" name="rating1" value="4.5" /><label class="half" for="star4half"></label>
<input type="radio" id="star4" name="rating1" value="4" /><label class = "full" for="star4"></label>
<input type="radio" id="star3half" name="rating1" value="3.5" /><label class="half" for="star3half"></label>
<input type="radio" id="star3" name="rating1" value="3" /><label class = "full" for="star3"></label>
<input type="radio" id="star2half" name="rating1" value="2.5" /><label class="half" for="star2half"></label>
<input type="radio" id="star2" name="rating1" value="2" /><label class = "full" for="star2"></label>
<input type="radio" id="star1half" name="rating1" value="1.5" /><label class="half" for="star1half"></label>
<input type="radio" id="star1" name="rating1" value="1" /><label class = "full" for="star1"></label>
<input type="radio" id="starhalf" name="rating1" value="0.5" /><label class="half" for="starhalf"></label>
</fieldset>
</div>
</div>
<div style="padding-top:20px;" class="row">
<div style="border-right: solid #4a98b5; width:290px;" class="col-
md-4"><p>Rate your experience</p></div>
<div style="font-size:20px;color:#FFD700" class="col-md-4">
<fieldset class="rating2">
<input type="radio" id="star5" name="rating2" value="5" /><label class = "full" for="star5" ></label>
<input type="radio" id="star4half" name="rating2" value="4.5" /><label class="half" for="star4half"></label>
<input type="radio" id="star4" name="rating2" value="4" /><label class = "full" for="star4"></label>
<input type="radio" id="star3half" name="rating2" value="3.5" /><label class="half" for="star3half"></label>
<input type="radio" id="star3" name="rating2" value="3" /><label class = "full" for="star3"></label>
<input type="radio" id="star2half" name="rating2" value="2.5" /><label class="half" for="star2half"></label>
<input type="radio" id="star2" name="rating2" value="2" /><label class = "full" for="star2"></label>
<input type="radio" id="star1half" name="rating2" value="1.5" /><label class="half" for="star1half"></label>
<input type="radio" id="star1" name="rating2" value="1" /><label class = "full" for="star1"></label>
<input type="radio" id="starhalf" name="rating2" value="0.5" /><label class="half" for="starhalf"></label>
</fieldset>
</div>
CSS
#import url(//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css);
.rating1 {
border: none;
float: left;
}
.rating1 > input { display: none; }
.rating1 > label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating1 > .half:before {
content: "\f089";
position: absolute;
}
.rating1 > label {
color: #ddd;
float: right;
}
.rating1 > input:checked ~ label, /* show gold star when clicked */
.rating1:not(:checked) > label:hover, /* hover current star */
.rating1:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */
.rating1 > input:checked + label:hover, /* hover current star when
changing rating */
.rating1 > input:checked ~ label:hover,
.rating1 > label:hover ~ input:checked ~ label, /* lighten current
selection */
.rating1 > input:checked ~ label:hover ~ label { color: #FFED85; }
.rating2 {
border: none;
float: left;
}
.rating2 > input { display: none; }
.rating2 > label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}
.rating2 > .half:before {
content: "\f089";
position: absolute;
}
.rating2 > label {
color: #ddd;
float: right;
}
.rating2 > input:checked ~ label, /* show gold star when clicked */
.rating2:not(:checked) > label:hover, /* hover current star */
.rating2:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */
.rating2 > input:checked + label:hover, /* hover current star when changing rating */
.rating2 > input:checked ~ label:hover,
.rating2 > label:hover ~ input:checked ~ label, /* lighten current selection */
.rating2 > input:checked ~ label:hover ~ label { color: #FFED85; }
Please have a look https://codepen.io/anon/pen/weYbzZ for the code.
Problem Solved!
Although the fieldsets have different class names, the input fields have the same names, hence when the second input field changes, it changes the first one. So different id names on the input fields solves the issue