Assuming you're talking about adding a glyph icon and not a background image to your input, you will need to use either the :before
or :after
pseudo elements to inject and position one, howwever note that these are not available for input
elements, so you will need to wrap your input
within e.g. a span
, then apply styling to this to add your placeholder icon. In the below example, I've simply added a small magnifying glass to the right hand side, though you can edit as appropriate.
HTML
<span class='search'><input type="text" class="inputtext" style="margin: 2px;" placeholder="Search" /></span>
CSS
.search{
display:inline-block;
position:relative;
}
.search:after{
display:inline-block;
position:absolute;
right:5px;
top:5px;
color:grey;
font-family:fontAwesome;
content:'\f002';
}
If you want the icon to appear on the left of the input, you need some additional CSS trickery:
input{
border:none;
padding-left:20px;
}
.search {
display:inline-block;
position:relative;
border:1px solid grey;
}
.search:after {
display:inline-block;
position:absolute;
left:3px;
top:3px;
color:grey;
font-family:fontAwesome;
content:'\f002';
}
Demo Fiddle (hiding the icon on focus)
If you wish to hide the icon on focus, you simply need to give the input a background color and a z-index with and without focus, the :focus
z-index should be high enough to force it to the front to display over the icon.
CSS:
input{
z-index:0;
position:relative;
}
.search{
display:inline-block;
position:relative;
}
.search:after{
display:inline-block;
position:absolute;
right:5px;
top:5px;
color:grey;
font-family:fontAwesome;
content:'\f002';
}
input:focus{
z-index:99;
}