Más de uno de nosotros nos hemos encontrado con crear un sistema de votos factible y práctico. Como vemos en Youtube o en Amazon. La mayoría de ejemplos que encontramos por la Web, estan desarrollados con JavaScript que funcionan correctamente bien, pero ya sabemos que si lo tenemos desactivado ya no nos sirve de mucho.

A continuación vemos como crear un sistema de votos o Rating Star únicamente con CSS, de esta manera evitaremos usar Scripts para conseguir el efecto deseado.

En el ejemplo solo se usa una imagen con 2 estrellas, una para el estado inicial y otra con el hover. De esta forma prescindimos de crear varias imágenes para cada valor de cada estrella. Debajo vemos el ejemplo ya funcionando.

Ejemplo del Sistema de votos:

HTML

1
2
3
4
5
6
7
<ul class="star-rating">
<li><a href="#" title="Valorar 1 de 5" class="one-star">1</a></li>		  
<li><a href="#" title="Valorar 2 de 5" class="two-stars">2</a></li>		  
<li><a href="#" title="Valorar 3 de 5" class="three-stars">3</a></li>		  
<li><a href="#" title="Valorar 4 de 5" class="four-stars">4</a></li>		  
<li><a href="#" title="Valorar 5 de 5" class="five-stars">5</a></li>
</ul>

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
.star-rating {
	list-style:none;
	margin: 0px;
	padding:0px;
	width: 100px;
	height: 20px;
	position: relative;
	background: url(star_rating.gif) top left repeat-x;		
}
.star-rating li {
	padding:0px;
	margin:0px;
	float: left;
}
.star-rating li a {
	display:block;
	width:20px;
	height: 20px;
	text-decoration: none;
	text-indent: -9000px;
	z-index: 20;
	position: absolute;
	padding: 0px;
}
.star-rating li a:hover {
	background: url(star_rating.gif) left bottom;
	z-index: 1;
	left: 0px;
}
.star-rating a.one-star {
	left: 0px;
}
.star-rating a.one-star:hover {
	width:20px;
}
.star-rating a.two-stars {
	left:20px;
}
.star-rating a.two-stars:hover {
	width: 40px;
}
.star-rating a.three-stars:hover {
	width: 60px;
}
.star-rating a.three-stars {
	left: 40px;
}
.star-rating a.four-stars {
	left: 60px;
}	
.star-rating a.four-stars:hover {
	width: 80px;
}
.star-rating a.five-stars {
	left: 80px;
}
.star-rating a.five-stars:hover {
	width: 100px;
}