El HTML
Vamos a aplicar esto a nuestra página. El HTML no es gran ciencia, simplemente utiliza tus <a>'s, <inputs>'s y/o <button>'s de manera normal y agregales clases. Para este tutorial usaré 2 clases por elemento: una que le diga que se trata de un botón de este tipo (box-link) y otra que le diga el color y el tamaño de dicho boton (color-tamaño):
En el ejemplo les pongo un ejemplo para cada uno de los elementos que les dije. Ahora vamos con el CSS.
El CSS
Vamos a empezar con la clase box-link. Vamos a darle estilo a nuestras tags. Tenemos que mostrar el elemento como un bloque, quitarle estilos que ya tenga por default (bordes, por ejemplo) y darle estilo a nuestra fuente:
- a.box-link:link, a.box-link:visited {
- display: block;
- margin: 10px auto;
- height: 40px;
- font-weight: bold;
- font-size: 15pt;
- line-height: 40px;
- text-align: center;
- border-bottom: 0
- }
- input.box-link, button.box-link {
- display: block;
- margin: 10px auto;
- border: 0;
- height: 40px;
- font-weight: normal;
- font-size: 15pt;
- line-height: 40px;
- text-align: center;
- color: #fff;
- border-bottom: 0
- }
Como ven, dividí el CSS para los hipervínculos y otro para el input y el button. Esto es solo por razones didácticas, no se fijen. Ahora solo vamos a agregar las clases para los colores/tamaños correspondientes. En estas clases solo vamos a agregar el color e imagen de fondo.
- .negro-210:link, .negro-210:visited {
- width: 210px;
- background: #000 url('negro-210x40.jpg') no-repeat top left;
- color: #fff
- }
- input.azul-160 {
- width: 160px;
- background: #09c url('azul-160x40.jpg') no-repeat top left;
- color: #fff
- }
- button.verde-110 {
- width: 110px;
- background: #81b638 url('verde-110x40.jpg') no-repeat top left;
- color: #fff
- }
Ya con eso tenemos unos bonitos links en cuadro, podemos agregar efectos al pasar el mouse encima (:hover); pero como son botones clickeables, preferí darles un estilo al dar click en ellos. Para esto usaremos la pseudo-clase :active que, lamentablemente, IE no soporta en los <inputs>'s ni en los <button>'s. Jodido IE. En fin; vamos a darle estilo a los demás:
- /* Empezemos con los anchors */
- a.box-link:active, input.box-link:active {
- background-position: 0 -40px;
- line-height: 43px;
- text-indent: 3px
- }
- a.negro-210:active {color: #999}
- /* Ahora vamos con los input y los button */
- input.box-link:active, button.box-link:active {
- background-position: 0 -40px;
- line-height: 43px;
- text-indent: 3px
- }
- input.azul-160:active {color: #98e8fc}
- button.verde-110:active {color: #dff178}
Lo que estamos haciendo es cambiar el color del botón y mover la imagen de fondo 40 pixeles hacia arriba así como mover el texto 3 pixeles a la derecha y 3 hacia abajo. Internet Explorer no cambiará de posición el fondo en los buttons o en los inputs; pero si moverá el texto 3 pixeles a la derecha, por lo que siguen quedando avisados los usuarios de este navegador que dieron click en ellos. Por accesibilidad no hay problema, por diseño si; pero al final lo importante queda intacto.
Por último y para variar, Internet Explorer 6 o menos tiene un pequeño bug que teine que ver con el line-height: 43px;. Lo que hace IE es hacer el contenedor de 43px de alto, mostrando parte del fondo que no debiera mostrarse. Así que, con el uso de comentarios condicionales tuve que agregar esto:
- <!--[if lte IE 6]>
- <style type="text/css">
- /* Arreglando bug en IE */
- a.box-link:active, input.box-link:active {
- line-height: 37px;
- padding-top: 3px;
- height: 37px
- }
- </style>
- <![endif]-->
Eso es todo para nuestros links. Agregando algunas clases más y usando todas las imagenes he creado un bonito demo con todas las tags arriba, además de todos los colores y tamaños. Les dejo el CSS completo aquí. Con este CSS pueden usar todos los colores y tamaños como lo hice en el demo:
- /* Divs de alineación */
- div.izquierda {
- width: 49%;
- margin: 20px 0 30px 0;
- float: left;
- clear: left;
- text-align: center
- }
- div.derecha {
- width: 49%;
- margin: 20px 0 30px 0;
- float: left;
- text-align: center
- }
- /* General links */
- a.box-link:link, a.box-link:visited, input.box-link {
- display: block;
- margin: 10px auto;
- height: 40px;
- font-weight: bold;
- font-size: 15pt;
- line-height: 40px;
- text-align: center;
- border-bottom: 0
- }
- /* Clickeando */
- a.box-link:active, input.box-link:active {
- background-position: 0 -40px;
- line-height: 43px;
- text-indent: 3px
- }
- a.negro-210:active, a.negro-160:active, a.negro-110:active {color: #999}
- a.azul-210:active, a.azul-160:active, a.azul-110:active {color: #98e8fc}
- a.verde-210:active, a.verde-160:active, a.verde-110:active {color: #dff178}
- a.amarillo-210:active, a.amarillo-160:active, a.amarillo-110:active {color: #ffec82}
- /* Tamaños */
- /* 210x40 */
- .negro-210:link, .negro-210:visited {
- width: 210px;
- background: #000 url('negro-210x40.jpg') no-repeat top left;
- color: #fff
- }
- .azul-210:link, .azul-210:visited {
- width: 210px;
- background: #09c url('azul-210x40.jpg') no-repeat top left;
- color: #fff
- }
- .verde-210:link, .verde-210:visited {
- width: 210px;
- background: #81b638 url('verde-210x40.jpg') no-repeat top left;
- color: #fff
- }
- .amarillo-210:link, .amarillo-210:visited {
- width: 210px;
- background: #e6a800 url('amarillo-210x40.jpg') no-repeat top left;
- color: #fff
- }
- /* 160x40 */
- .negro-160:link, .negro-160:visited {
- width: 160px;
- background: #000 url('negro-160x40.jpg') no-repeat top left;
- color: #fff
- }
- .azul-160:link, .azul-160:visited {
- width: 160px;
- background: #09c url('azul-160x40.jpg') no-repeat top left;
- color: #fff
- }
- .verde-160:link, .verde-160:visited {
- width: 160px;
- background: #81b638 url('verde-160x40.jpg') no-repeat top left;
- color: #fff
- }
- .amarillo-160:link, .amarillo-160:visited {
- width: 160px;
- background: #e6a800 url('amarillo-160x40.jpg') no-repeat top left;
- color: #fff
- }
- /* 110x40 */
- .negro-110:link, .negro-110:visited {
- width: 110px;
- background: #000 url('negro-110x40.jpg') no-repeat top left;
- color: #fff
- }
- .azul-110:link, .azul-110:visited {
- width: 110px;
- background: #09c url('azul-110x40.jpg') no-repeat top left;
- color: #fff
- }
- .verde-110:link, .verde-110:visited {
- width: 110px;
- background: #81b638 url('verde-110x40.jpg') no-repeat top left;
- color: #fff
- }
- .amarillo-110:link, .amarillo-110:visited {
- width: 110px;
- background: #e6a800 url('amarillo-110x40.jpg') no-repeat top left;
- color: #fff
- }
- /* Formularios */
- /* General */
- input.box-link, button.box-link {
- display: block;
- margin: 10px auto;
- border: 0;
- height: 40px;
- font-weight: normal;
- font-size: 15pt;
- line-height: 40px;
- text-align: center;
- color: #fff;
- border-bottom: 0
- }
- /* Clickeando */
- input.box-link:active, button.box-link:active {
- background-position: 0 -40px;
- line-height: 43px;
- text-indent: 3px
- }
- input.negro-210:active, input.negro-160:active, input.negro-110:active,
- button.negro-210:active, button.negro-160:active, button.negro-110:active
- {color: #999}
- input.azul-210:active, input.azul-160:active, input.azul-110:active,
- button.azul-210:active, button.azul-160:active, button.azul-110:active
- {color: #98e8fc}
- input.verde-210:active, input.verde-160:active, input.verde-110:active,
- button.verde-210:active, button.verde-160:active, button.verde-110:active
- {color: #dff178}
- input.amarillo-210:active, input.amarillo-160:active, input.amarillo-110:active,
- button.amarillo-210:active, button.amarillo-160:active, button.amarillo-110:active
- {color: #ffec82}
- /* 210x40 */
- input.negro-210, button.negro-210 {
- width: 210px;
- background: #000 url('negro-210x40.jpg') no-repeat top left;
- color: #fff
- }
- input.azul-210, button.azul-210 {
- width: 210px;
- background: #09c url('azul-210x40.jpg') no-repeat top left;
- color: #fff
- }
- input.verde-210, button.verde-210 {
- width: 210px;
- background: #81b638 url('verde-210x40.jpg') no-repeat top left;
- color: #fff
- }
- input.amarillo-210, button.amarillo-210 {
- width: 210px;
- background: #e6a800 url('amarillo-210x40.jpg') no-repeat top left;
- color: #fff
- }
- /* 160x40 */
- input.negro-160, button.negro-160 {
- width: 160px;
- background: #000 url('negro-160x40.jpg') no-repeat top left;
- color: #fff
- }
- input.azul-160, button.azul-160 {
- width: 160px;
- background: #09c url('azul-160x40.jpg') no-repeat top left;
- color: #fff
- }
- input.verde-160, button.verde-160 {
- width: 160px;
- background: #81b638 url('verde-160x40.jpg') no-repeat top left;
- color: #fff
- }
- input.amarillo-160, button.amarillo-160 {
- width: 160px;
- background: #e6a800 url('amarillo-160x40.jpg') no-repeat top left;
- color: #fff
- }
- /* 110x40 */
- input.negro-110, button.negro-110 {
- width: 110px;
- background: #000 url('negro-110x40.jpg') no-repeat top left;
- color: #fff
- }
- input.azul-110, button.azul-110 {
- width: 110px;
- background: #09c url('azul-110x40.jpg') no-repeat top left;
- color: #fff
- }
- input.verde-110, button.verde-110 {
- width: 110px;
- background: #81b638 url('verde-110x40.jpg') no-repeat top left;
- color: #fff
- }
- input.amarillo-110, button.amarillo-110 {
- width: 110px;
- background: #e6a800 url('amarillo-110x40.jpg') no-repeat top left;
- color: #fff
- }
Espero les sea de utilidad. Luego me meto un poco más con los formularios, que tenemos muchos elementos que podemos estilizar.
Por cierto, no está de más enlazar a esta entrada de anieto2k, en donde discute el si usar <button> (Que es semánticamente correcto) o <input> (Que es Internet-Explorer correcto... ).
Jooo!!!
esta genial!
lo pondre a prueba cuando vuelva a subir mi sitio =)
saludos y muchas gracias por este genial post =D
Simplemente genial.
felicitanes, relamente unmuy buen rtrabajo en diseño e implementacion
salud2
Muy bueno el artículo, es practico que es, me ha sido de gran ayuda, muchas gracias.
Salud.
Wow! Bonitos los diseños
Lo aplicare en mi formulario de contacto
Gracias!
Muy buen aporte, lo usare en mi web
gracias!
saludos desde méxico
Excelente articulo, estaria genial que pusieras mas tutos de fireworks
Olle podrias dejar la descarga de los botones?