How do I put an icon inside a form's input element?
Got me?
The site you linked uses a combination of CSS tricks to pull this off. First, it uses a background-image for the <input>
element. Then, in order to push the cursor over, it uses padding-left
.
In other words, they have these two CSS rules:
background: url(images/comment-author.gif) no-repeat scroll 7px 7px;
padding-left:30px;
Just use the background property in your CSS.
<input id="foo" type="text" />
#foo
{
background: url(/img/foo.png);
}
You can try this:
input[type='text'] {
background-image: url(images/comment-author.gif);
background-position: 7px 7px;
background-repeat: no-repeat;
}
The CSS solutions posted by others are the best way to accomplish this.
If that should give you any problems (read IE6), you can also use a borderless input inside of a div.
<div style="border: 1px solid #DDD;">
<img src="icon.png"/>
<input style="border: none;"/>
</div>
Not as "clean", but should work on older browsers.