Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put icon inside input element in a form (not as background image!) [closed]

I want to do exactly what was asked here:

Put icon inside input element in a form

Except that I want the icons to be right-aligned.

The "background" workaround won't work, since those images have to be clickable! So it must be an IMG.

How can I do this?

like image 432
John Smith Avatar asked Dec 17 '13 13:12

John Smith


People also ask

How do you put an icon into an input element?

To add icon inside the input element the <i> tag and <span> tag are used widely to add icons on the webpages. To add any icons on the webpages or in some specific area, it needs the fontawesome link inside the head tag. The fontawesome icon can be placed by using the fa prefix before the icon's name.

How do you add an icon to a form field?

Open our free Bootstrap Form Builder in your browser. Add a field from the "Add a Field" tab. Select "Icon" from the Prepend or Append dropdown in the "Edit Fields" tab. Choose an icon from the icon picker window.

How do you put an icon in HTML?

To insert an icon, add the name of the icon class to any inline HTML element. The <i> and <span> elements are widely used to add icons. All the icons in the icon libraries below, are scalable vector icons that can be customized with CSS (size, color, shadow, etc.)


2 Answers

A solution without background-images:

JSFiddle.

#input_container {       position:relative;      padding:0;      margin:0;  }  #input {       height:20px;      margin:0;      padding-left:30px;  }  #input_img {      position:absolute;      bottom:8px;      left:10px;      width:10px;      height:10px;  }
<div id="input_container">      <input type="text" id="input" value>      <img src="https://cdn1.iconfinder.com/data/icons/CornerStone/PNG/arrow%20right.png" id="input_img">  </div>
like image 79
display-name-is-missing Avatar answered Sep 16 '22 21:09

display-name-is-missing


You can use a div as a wrapper, containing an image and input field, and position the image inside there that overlay's the input field using position absolute.

HTML

<div>     <img src="http://static4.wikia.nocookie.net/__cb20131121214007/destinypedia/images/7/71/Information_Icon.svg" alt="">     <input type="text"> </div> 

CSS

div {     height:30px;     width:300px;     position:relative; }  img {     height:15px;     position:absolute;     right:0;     top:5px; }  input {     width:100%; } 

FIDDLE

http://jsfiddle.net/aTvvN/1/

like image 31
koningdavid Avatar answered Sep 16 '22 21:09

koningdavid