<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>2E5E &#187; button</title>
	<atom:link href="http://11870.com/2e5e/tag/button/feed/" rel="self" type="application/rss+xml" />
	<link>http://11870.com/2e5e</link>
	<description>blog del equipo de tecnología de 11870.com</description>
	<lastBuildDate>Thu, 09 Feb 2012 09:44:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>cómo crear botones de formulario más atractivos</title>
		<link>http://11870.com/2e5e/2009/05/14/como-crear-botones-de-formulario-mas-atractivos/</link>
		<comments>http://11870.com/2e5e/2009/05/14/como-crear-botones-de-formulario-mas-atractivos/#comments</comments>
		<pubDate>Thu, 14 May 2009 15:20:23 +0000</pubDate>
		<dc:creator>arctarus</dc:creator>
				<category><![CDATA[front-end]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[eye candy]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[formulario]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://11870.com/2e5e/?p=253</guid>
		<description><![CDATA[La investigación en la atención, persuasión, elección, felicidad, aprendizaje, y otros temas similares nos demuestran que un diseño más atractivo es también más usable para la mayoría de la gente, por lo que decidimos que deberíamos mejorar el aspecto de nuestros formularios. Uno de los elementos de formulario que nos ha dado algún quebradero de [...]]]></description>
			<content:encoded><![CDATA[<p>La investigación en la atención, persuasión, elección, felicidad, aprendizaje, y otros temas similares nos demuestran que un diseño más atractivo es también más usable para la mayoría de la gente, por lo que decidimos que deberíamos mejorar el aspecto de nuestros formularios.</p>
<p>Uno de los elementos de formulario que nos ha dado algún quebradero de cabeza ha sido el botón de <em>submit</em>. Si queríamos mejorar su aspecto visual añadiéndole un toque más <em>dospuntocerista</em> necesitábamos hacer alguna artimaña, por lo que pensamos que la mejor solución era sustituir el elemento <em>input type=&#8221;submit&#8221;</em> por un <em>button </em>y ya que su función dentro del formulario va a ser enviar los datos qué mejor que<em> el type=&#8221;submit&#8221;</em>, la razón queda muy clara en la <cite><a href="http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.5">especificación del W3C sobre el elemento button</a></cite>.</p>
<blockquote><p>&#8220;Los botones creados con el elemento BUTTON funcionan exactamente como los botones creados con el elemento INPUT, pero ofrecen la posibilidad de un renderizado mejorado.&#8221;</p></blockquote>
<p>Para empezar hicimos una sustitución directa:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>enviar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>y luego nos pusimos a añadirle degradado y bordes redondeados, para lo cual usamos la clásica técnica de tener dos imágenes: una más grande (en nuestro caso de 300px de ancho) en el lado izquierdo, y otra mucho más pequeña en el lado derecho, añadiendo el siguiente html:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;button</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;overmarked&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>enviar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/span<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/button<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>y css:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">button span<span style="color: #6666ff;">.overmarked</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_left.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span>
button span<span style="color: #6666ff;">.overmarked</span> span <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span> <span style="color: #933;">14px</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_right.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>La razón para incluir bajo el elemento button dos <em>span</em> en lugar de los clásicos <em>div&#8217;s</em> es que los elementos de línea no deben contener elementos de bloque en su interior.</p>
<p>El primer problema a resolver sería eliminar el borde y el fondo del <em>button</em> que queda alrededor de nuestro maravilloso botón y recuperar el cursor con forma de mano que caracteriza a los elementos <em>clickables</em>, para lo que añadimos la siguiente regla:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">button <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">visible</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Las propiedades width y overflow se han añadido para eliminar los espacios extra que añade IE6 y IE7 a los <em>buttons</em>. Está todo muy bien explicado en <a href="http://jehiah.cz/archive/button-width-in-ie">Button Width in IE</a>.</p>
<p>Y para finalizar pasamos a definir las reglas CSS para soportar cada uno de los estados que debe tener un botón: <em>hover</em>, <em>active</em> y <em>disabled</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">button<span style="color: #3333ff;">:hover </span>span<span style="color: #6666ff;">.overmarked</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_hover_left.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span>
button<span style="color: #3333ff;">:hover </span>span<span style="color: #6666ff;">.overmarked</span> span <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_hover_right.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span>
button<span style="color: #3333ff;">:active </span>span<span style="color: #6666ff;">.overmarked</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_active_left.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span>
button<span style="color: #3333ff;">:active </span>span<span style="color: #6666ff;">.overmarked</span> span <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_active_right.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span> 
button<span style="color: #6666ff;">.disabled</span> span<span style="color: #6666ff;">.overmarked</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_disabled_left.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span>
button<span style="color: #6666ff;">.disabled</span> span<span style="color: #6666ff;">.overmarked</span> span <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">/imgs/bck_submit_disabled_right.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">right</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>La clase <em>disabled</em> se añade con <em>javascript</em> en el momento de realizar el <em>submit</em> del formulario y nos sirve además para evitar que se envíe el formulario más de una vez por error.</p>
<p>Finalmente, y para redondear la jugada eliminamos el <em>outline</em> extra al recibir el foco del <em>button</em> que añaden los navegadores basados en <em>gecko</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">button<span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner </span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>El resultado debe ser algo así lo que se puede ver en nuestro <a href="http://11870.com/biz/perform-request/aire-acondicionado#submit">formulario de pedidos</a>.</p>
<p><strong>actualización 18/05/09</strong><br />
Después de leer <a href="http://www.456bereastreet.com/archive/200905/do_not_remove_the_outline_from_links_and_form_controls/" title="ir a 456 berea street">Do not remove the outline from links and form controls</a> hemos decidido retractarnos de la eliminación del <em>outline</em> de nuestro botón para así permitir la navegación de la página a través del teclado y la página no deje de ser accesible.</p>
<p><strong>referencias</strong></p>
<ul>
<li><a href="http://www.alistapart.com/articles/indefenseofeyecandy">In Defense of Eye Candy</a></li>
<li><a href="http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.5">especificación del W3C sobre el elemento button</a></li>
<li><a href="http://jehiah.cz/archive/button-width-in-ie">Button Width in IE</a></li>
<li><a href="http://www.456bereastreet.com/archive/200905/do_not_remove_the_outline_from_links_and_form_controls/" title="ir a 456 berea street">Do not remove the outline from links and form controls</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://11870.com/2e5e/2009/05/14/como-crear-botones-de-formulario-mas-atractivos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

