Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Icon in bootstrap 4 inside the input

I am looking for a solution to create and input like this one in bootstrap 4 Desired target

I am using font awesome and this is the code that I use

<div class="input-group">     <label class="control-label">Username</label>     <input type="text" class="form-control" placeholder="Username" />     <span>         <i class="fa fa-user-circle-o" aria-hidden="true"></i>     </span> </div> 

but i get the image out of the input Any help please https://jsfiddle.net/5db2ho62/

like image 276
Mohamed Sherif Noureldin Avatar asked May 29 '17 13:05

Mohamed Sherif Noureldin


People also ask

How do you put an icon inside a input field?

In HTML, icons are added with the <i> tag. For it to be added inside the input elements, it must be added between the closing and opening tags of the elements in which you want the icon to be displayed.

How add icon inside field in react Bootstrap?

Just wrap your <Form. Control> in an <InputGroup> and add a <InputGroup. Prepend> , which will contain the icon you wish to include.

Does Bootstrap 4 have icons?

Bootstrap 4 does not have its own icon library (Glyphicons from Bootstrap 3 are not supported in BS4). However, there are many free icon libraries to choose from, such as Font Awesome and Google Material Design Icons.


2 Answers

here is the solution

span{    position: absolute;    margin-left: 5px;    height: 25px;    display: flex;    align-items: center;  }  input{    padding-left: 25px;    height: 20px;  }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>    <div class="input-group">    <span>      <i class="fa fa-user-circle-o" aria-hidden="true"></i>    </span>    <input type="text" class="form-control" placeholder="Username" />  </div>

here is the working fiddle

like image 66
Syam Pillai Avatar answered Sep 30 '22 06:09

Syam Pillai


.main {      width: 50%;      margin: 50px auto;  }    .form-group .form-control {      padding-left: 2.375rem;  }    .form-group .form-control-icon {      position: absolute;      z-index: 2;      display: block;      width: 2.375rem;      height: 2.375rem;      line-height: 2.375rem;      text-align: center;      pointer-events: none;      color: #aaa;  }
<link id="bootstrap-css" href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">    <div class="main">    <div class="form-group">      <span class="fa fa-search form-control-icon"></span>      <input type="text" class="form-control" placeholder="Search">    </div>    </div>

Try it!

like image 39
Kimprosh Avatar answered Sep 30 '22 07:09

Kimprosh