Star Rating Html, Css
I did stuck here and need help. How can I use a tag for for each button? Can somebody help me to finish this star rating code? 'For each button use only a single a tag, with as man
Solution 1:
Html code:
<fieldset class="rating">
<inputtype="radio"id="star5"name="rating"value="5" /><labelclass = "full"for="star5"title="Awesome - 5 stars"></label><inputtype="radio"id="star4half"name="rating"value="4 and a half" /><labelclass="half"for="star4half"title="Pretty good - 4.5 stars"></label><inputtype="radio"id="star4"name="rating"value="4" /><labelclass = "full"for="star4"title="Pretty good - 4 stars"></label><inputtype="radio"id="star3half"name="rating"value="3 and a half" /><labelclass="half"for="star3half"title="Meh - 3.5 stars"></label><inputtype="radio"id="star3"name="rating"value="3" /><labelclass = "full"for="star3"title="Meh - 3 stars"></label><inputtype="radio"id="star2half"name="rating"value="2 and a half" /><labelclass="half"for="star2half"title="Kinda bad - 2.5 stars"></label><inputtype="radio"id="star2"name="rating"value="2" /><labelclass = "full"for="star2"title="Kinda bad - 2 stars"></label><inputtype="radio"id="star1half"name="rating"value="1 and a half" /><labelclass="half"for="star1half"title="Meh - 1.5 stars"></label><inputtype="radio"id="star1"name="rating"value="1" /><labelclass = "full"for="star1"title="Sucks big time - 1 star"></label><inputtype="radio"id="starhalf"name="rating"value="half" /><labelclass="half"for="starhalf"title="Sucks big time - 0.5 stars"></label>
css file :
@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; }
.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; }
Kindly check this code might be helpful
Solution 2:
I want to point out a much cleaner solution for CSS only star ratings. I am covering a form input field as well as a simple showcase element. I've also written a blog post with more details and a codepen.
// Colors$star-color: #FFC600;
// Star definitions
%full-star {
&:after {
font-family: "FontAwesome";
content: "\f005";
}
};
%half-star {
&:after {
font-family: "FontAwesome";
content: "\f123";
}
};
%empty-star {
&:after {
font-family: "FontAwesome";
content: "\f006";
}
};
// 5 Star Rating Showcase.rating-score {
display: inline-flex;
flex-direction: row;
align-items: flex-start;
margin: 0;
padding: 0;
color: $star-color;
.rating-score-item {
font-size: inherit;
margin: 0;
padding: 0;
display: block;
font-size: 1.5em;
@extend %empty-star;
}
@for$i from 1 through 5 {
&[data-rating='#{$i}'] {
.rating-score-item:nth-child(-n + #{$i}) {
@extend %full-star;
}
}
}
@for$i from 0 through 4 {
&[data-rating='#{$i + 0.5}'] {
.rating-score-item:nth-child(-n + #{$i}) {
@extend %full-star;
}
.rating-score-item:nth-child(#{$i + 1}) {
@extend %half-star;
}
}
}
}
<ulclass="rating-score"data-rating="4"><liclass="rating-score-item"></li><liclass="rating-score-item"></li><liclass="rating-score-item"></li><liclass="rating-score-item"></li><liclass="rating-score-item"></li></ul>
Post a Comment for "Star Rating Html, Css"