Question

I have to implement a Star rating Feedback on articles in Visualforce page . I have seen the code in http://codepen.io/rogie/pen/GIfqc which perfectly suits my requirement . But don't know why it doesn't work when i put the whole code in a file and execute . Also it doesn't work in Firefox . Can anyone help me out here..??

@IamDesai - Here is my code

<html>
<head>
<style>

.star-rating{
font-size:0;
white-space:nowrap;
display:inline-block;
width:250px;
height:50px;
overflow:hidden;
position:relative;
background:
url('data:image/svg+xml;utf-8,<svg version="1.1" xmlns="http://www.w3.org/2000/svg"     xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="20px" height="20px"     viewBox="0 0 20 20" enable-background="new 0 0 20 20" xml:space="preserve"><polygon     fill="#DDDDDD" points="10,0 13.09,6.583 20,7.639 15,12.764 16.18,20 10,16.583 3.82,20 5,12.764 0,7.639 6.91,6.583 "/></svg>');
background-size: contain;
}
i{
opacity: 0;
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 20%;
z-index: 1;
background: 
    url('data:image/svg+xml;utf-8,<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="20px" height="20px" viewBox="0 0 20 20" enable-background="new 0 0 20 20" xml:space="preserve"><polygon fill="#FFDF88" points="10,0 13.09,6.583 20,7.639 15,12.764 16.18,20 10,16.583 3.82,20 5,12.764 0,7.639 6.91,6.583 "/></svg>');  
background-size: contain;
}
input{ 
-moz-appearance:none;
-webkit-appearance:none;
opacity: 0;
display:inline-block;
width: 20%;
height: 100%; 
margin:0;
padding:0;
z-index: 2;
position: relative;
&:hover + i,
&:checked + i{
opacity:1;    
}
}
i ~ i{
width: 40%;
}
i ~ i ~ i{
width: 60%;
}
i ~ i ~ i ~ i{
width: 80%;
}
i ~ i ~ i ~ i ~ i{
width: 100%;
}
}


.choice{
position: fixed;
top: 0;
left:0;
right:0;
text-align: center;
padding: 20px;
display:block;
}

*, ::after, ::before{
height: 100%;
padding:0;
margin:0;
box-sizing: border-box;
text-align: center;  
vertical-align: middle;
}

body{
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", 
Helvetica, Arial, "Lucida Grande", sans-serif;
&::before{
height: 100%;
content:'';
width:0;
background:red;
vertical-align: middle;
display:inline-block;
}
}

</style>

<script type="text/javascript">$(':radio').change(
function(){
$('.choice').text( $(this).val() + ' stars' );
} 
)</script>

</head>
<body>
<strong class="choice">Choose a rating</strong><br>
<span class="star-rating">
<input type="radio" name="rating" value="1"><i></i>
<input type="radio" name="rating" value="2"><i></i>
<input type="radio" name="rating" value="3"><i></i>
<input type="radio" name="rating" value="4"><i></i>
<input type="radio" name="rating" value="5"><i></i>
</span>

</body>
</html>
Was it helpful?

Solution

hear is a working fiddle StarFiddle and you need to include

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>

Single file do you want this.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Star</title>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
.star-rating {
font-size: 0;
white-space: nowrap;
display: inline-block;
width: 250px;
height: 50px;
overflow: hidden;
position: relative;
background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDIwIDIwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cG9seWdvbiBmaWxsPSIjREREREREIiBwb2ludHM9IjEwLDAgMTMuMDksNi41ODMgMjAsNy42MzkgMTUsMTIuNzY0IDE2LjE4LDIwIDEwLDE2LjU4MyAzLjgyLDIwIDUsMTIuNzY0IDAsNy42MzkgNi45MSw2LjU4MyAiLz48L3N2Zz4=');
background-size: contain;
}
.star-rating i {
opacity: 0;
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 20%;
z-index: 1;
background: url('data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMjBweCIgaGVpZ2h0PSIyMHB4IiB2aWV3Qm94PSIwIDAgMjAgMjAiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDIwIDIwIiB4bWw6c3BhY2U9InByZXNlcnZlIj48cG9seWdvbiBmaWxsPSIjRkZERjg4IiBwb2ludHM9IjEwLDAgMTMuMDksNi41ODMgMjAsNy42MzkgMTUsMTIuNzY0IDE2LjE4LDIwIDEwLDE2LjU4MyAzLjgyLDIwIDUsMTIuNzY0IDAsNy42MzkgNi45MSw2LjU4MyAiLz48L3N2Zz4=');
background-size: contain;
}
.star-rating input {
-moz-appearance: none;
-webkit-appearance: none;
opacity: 0;
display: inline-block;
width: 20%;
height: 100%;
margin: 0;
padding: 0;
z-index: 2;
position: relative;
}
.star-rating input:hover + i,
.star-rating input:checked + i {
opacity: 1;
}
.star-rating i ~ i {
width: 40%;
}
.star-rating i ~ i ~ i {
width: 60%;
}
.star-rating i ~ i ~ i ~ i {
width: 80%;
}
.star-rating i ~ i ~ i ~ i ~ i {
width: 100%;
}
.choice {
position: fixed;
top: 0;
left: 0;
right: 0;
text-align: center;
padding: 20px;
display: block;
}
*,
::after,
::before {
height: 100%;
padding: 0;
margin: 0;
box-sizing: border-box;
text-align: center;
vertical-align: middle;
}
body {
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
}
body::before {
height: 100%;
content: '';
width: 0;
background: red;
vertical-align: middle;
display: inline-block;
}
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$(':radio').change(
function(){
console.log(this.value);
$('.choice').text( this.value + ' stars' );
}
)
});//]]>
</script>
</head>
<body>
<span class="star-rating">
<input type="radio" name="rating" value="1"><i></i>
<input type="radio" name="rating" value="2"><i></i>
<input type="radio" name="rating" value="3"><i></i>
<input type="radio" name="rating" value="4"><i></i>
<input type="radio" name="rating" value="5"><i></i>
</span>
<strong class="choice">Choose a rating</strong>
</body>
</html>

OTHER TIPS

Try raty plugin for rating .. Read Documents and Demo sample

You havent included jQuery in your code above. Just add this line to your code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<html>
<head>
<style>
@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;  } 
</style>
</head>

<body>
<h1>Pure CSS Star Rating Widget</h1>
<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>
</body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top