<?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>x + 3 &#187; forms</title>
	<atom:link href="http://xplus3.net/tag/forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://xplus3.net</link>
	<description></description>
	<lastBuildDate>Fri, 19 Aug 2011 01:05:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Images for Form Submit Buttons Using CSS</title>
		<link>http://xplus3.net/2009/12/10/images-for-form-submit-buttons-using-css/</link>
		<comments>http://xplus3.net/2009/12/10/images-for-form-submit-buttons-using-css/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 20:11:16 +0000</pubDate>
		<dc:creator>Jonathan Brinley</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[buttons]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[forms]]></category>

		<guid isPermaLink="false">http://xplus3.net/?p=248</guid>
		<description><![CDATA[Browsers&#8217; default submit buttons can be boring, ugly, or just not match your site. Whatever your reason, it would be nice to dress up the buttons using CSS when you don&#8217;t want to (or can&#8217;t) change the HTML to use &#60;input type="image" /&#62; I&#8217;ve been struggling to find a way to do it in a cross-browser way, and just recently &#8230; <a href="http://xplus3.net/2009/12/10/images-for-form-submit-buttons-using-css/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Browsers&#8217; default submit buttons can be boring, ugly, or just not match your site. Whatever your reason, it would be nice to dress up the buttons using CSS when you don&#8217;t want to (or can&#8217;t) change the HTML to use <code>&lt;input type="image" /&gt;</code></p>
<p>I&#8217;ve been struggling to find a way to do it in a cross-browser way, and just recently stumbled upon the answer.<br />
<span id="more-248"></span></p>
<h3>The Problem</h3>
<p>Assume the following HTML snippet:</p>
<pre>
&lt;form action="" method="post"&gt;
  &lt;div class="form-submit"&gt;
    &lt;input type="submit" name="submit" value="Submit" /&gt;
  &lt;/div&gt;
&lt;/form&gt;</pre>
<p>Here&#8217;s my first attempt at CSS for the submit button (assume, here, that I have a 101x39px image to use for the submit button):</p>
<pre>form .form-submit input {
  display: block;
  width: 101px;
  height: 39px;
  background-color: transparent;
  background-image: url(submit.png);
  background-repeat: no-repeat;
  background-position: 0 0;
  padding: 0;
  margin: 0;
  border: none;
  cursor: pointer;
  text-indent: -9000px;
}</pre>
<p>Not to bad. It&#8217;s a standard CSS image replacement technique with a few small additions to override some default button styles. But in IE7 and below, the button disappears. Why is that? It seems the <code>text-indent</code> is applied to the whole <code>input</code>, sending it far off the screen.</p>
<p>So what if we remove that <code>text-indent</code>? As you might have guessed, the text still appears on top of the image. Even if we set <code>text-indent: 0</code> in a conditional comment for IE7 and below, you still have a problem for those browsers.</p>
<p>So what about putting the image into the padding, instead? </p>
<pre>
  text-indent: 0;
  padding: 39px 0 0 0;
  height: 0;
</pre>
<p>Once again, the button disappears in IE7 and below.</p>
<h3>The Solution</h3>
<p>But, what if one day you make a mistake? What if you forget to set <code>height</code> to <code>0</code> when you add the <code>padding-top</code>? Amazingly, you don&#8217;t get a 78px tall element; it remains 39px tall in all browsers (where all includes IE8, IE7, IE6, Firefox 3.5, Chrome 3, Safari 4, and Opera 10)! Why is that? I have no idea, but it works.</p>
<p>One problem still remains, though. In Opera, the text is still visible on top of the image. So we return to our good friend <code>text-indent</code>. Set it to an arbitrarily large negative number, but keep it at 0 for IE7 and below using CSS in a conditional comment. The button should now be replaced with an image in all browsers.</p>
<pre>form .form-submit input {
  display: block;
  width: 101px;
  height: 39px;
  background-color: transparent;
  background-image: url(submit.png);
  background-repeat: no-repeat;
  background-position: 0 0;
  padding: 39px 0 0 0;
  border: none;
  cursor: pointer;
  text-indent: -9000px;
}</pre>
<p>And don&#8217;t forget, in your <code>IE lte 7</code> conditional stylesheet:</p>
<pre>
form .form-submit input {
  text-indent: 0;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://xplus3.net/2009/12/10/images-for-form-submit-buttons-using-css/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

