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.
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> |
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; } |
Si quieres seguir las respuestas de este artículo: subscríbete a las respuestas.
Puedes dejar un comentario, o hacer trackback desde tu propio sitio Web.
Pedro
Junio 4th, 2010. Hora: 18:59
Hola, gracias por la informacíon! pero quería preguntarte algo.
Me podrías decir de qué forma puedo hacer que funcione en blogger?
Te estaría muy agradecido si me hecharas una mano, y si me contestaras por E-mail muchisimo mejor.
Gracias de antemano, saludos