title: How can I apply a background image to a text input without losing the default border in Firefox and WebKit browsers?
body: <p>For some reason most modern browsers will stop applying their default input border style to text boxes if you give them a background image. Instead you get that ugly inset style. From what I can tell there's no CSS way to apply the default browser style either.</p>
  
  <p>IE 8 doesn't have this problem. Chrome 2 and Firefox 3.5 do and I assume other browsers as well. From what I've read online IE 7 has the same problem, but that post didn't have a solution.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;style&gt;
      .pictureInput {
        background-image: url(http://storage.conduit.com/images/searchengines/search_icon.gif);
        background-position: 0 1px;
        background-repeat: no-repeat;
      }
    &lt;/style&gt;
  &lt;body&gt;
    &lt;input type="text" class="pictureInput" /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    &lt;input type="text"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In Chrome 2 it looks like this: <a href="http://www.screencast.com/users/jadeonly/folders/Snagit/media/d4ee9819-c92a-4bc2-b84e-e3a4ed6843b6" rel="nofollow noreferrer">http://www.screencast.com/users/jadeonly/folders/Snagit/media/d4ee9819-c92a-4bc2-b84e-e3a4ed6843b6</a></p>
  
  <p>And in Firefox 3.5: <a href="http://www.screencast.com/users/jadeonly/folders/Snagit/media/d70dd690-9273-45fb-9893-14b38202ddcc" rel="nofollow noreferrer">http://www.screencast.com/users/jadeonly/folders/Snagit/media/d70dd690-9273-45fb-9893-14b38202ddcc</a></p>
  
  <p><strong>Update: JS Solution:</strong> I'm still hoping to find a pure CSS-on-the-input solution, but here's the workaround I'll use for now. Please note this is pasted right out of my app so isn't a nice, stand alone example like above. I've just included the relevant parts out of my large web app. You should be able to get the idea. The HTML is the input with the "link" class. The large vertical background position is because it's a sprite. Tested in IE6, IE7, IE8, FF2, FF3.5, Opera 9.6, Opera 10, Chrome 2, Safari 4. I need to tweak the background position a couple pixels in some browsers still:</p>
  
  <p>JS:</p>
  
  <pre><code> $$('input.link').each(function(el) {
     new Element('span',{'class':'linkIcon'}).setText(' ').injectBefore(el);
     if (window.gecko) el.setStyle('padding', '2px 2px 2px 19px');
   });
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>input.link { padding-left: 19px; }
  span.linkIcon { z-index: 2; width: 19px; height: 19px; position: absolute; background-image: url(img/fields.gif); background-position: 1px -179px; background-repeat: no-repeat; }
  </code></pre>
  
  <p><strong>Update: CSS Close Enough Solution:</strong> Based on the suggestion from kRON here's the CSS to make the inputs match FF and IE in Vista which makes a good choice if you decide to give up on pure defaults and enforce one style. I have modified his slightly and added the "blueish" effects:</p>
  
  <p>CSS:</p>
  
  <pre><code>input[type=text], select, textarea {
      border-top: 1px #acaeb4 solid;
      border-left: 1px #dde1e7 solid;
      border-right: 1px #dde1e7 solid;
      border-bottom: 1px #e3e9ef solid;
      -moz-border-radius: 2px;
      -webkit-border-radius: 2px;
      padding: 2px;
  }
  input[type=text]:hover, select:hover, textarea:hover, input[type=text]:focus, select:focus, textarea:focus {
      border-top: 1px #5794bf solid;
      border-left: 1px #c5daed solid;
      border-right: 1px #b7d5ea solid;
      border-bottom: 1px #c7e2f1 solid;
  }
  select { border: 1px; }
  </code></pre>