0

I was trying to use font awesome and place it inside a search box.

I used the ff html:

<form class="form-inline my-2 my-lg-0">
    <input
      class="form-control mr-sm-2 search"
      type="search"
      placeholder="Search.."
      aria-label="Search"
    />
</form>

And then to control the layout of the search I place the ff CSS:

input.form-control.mr-sm-2.search{
    outline: none;
    border: none;
    font-size: 12px;
    border-radius: 2px;
    position: relative;
}



input.form-control.mr-sm-2.search:before{
    content: "\f002";
    font-family: 'FontAwesome';
    font-style: normal;
    font-weight: normal;
    text-decoration: inherit;
    color: #000;
    font-size: 13px;
    padding-right: 15px;
    position: absolute;
    top: 15px;
    left: 0;
}

Any idea why the font awesome icon don't work?

4 Answers4

0

Did you check by F12 and see console tab? It may be you missing font file and image file. You should use CDN link:

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
  • yes https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.cs I use this. –  Feb 14 '19 at 07:34
0

I checked some and following could help you.

Put a font-awesome icon inside an input tag

try this

Hariharan V.
  • 191
  • 1
  • 3
  • 18
0

:before or other pseudo classes does not work on self closing elements sucs as <br/>, <img /> or <input /> tags

You can do this as follows

.search-wrap{
  position: relative;
  border: 1px solid #ccc;
  padding: 10px;
  border-radius: 5px;
  max-width: 200px;
}
.search-wrap input{
  border: 0px;
  padding-left: 20px;
}
.search-wrap i.fa{
  position: absolute;
  left: 10px;
  top:10px;
}
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">

<div class="search-wrap">
  <input class="form-control" type="text" Placeholder="Search here.." />
  <i class="fa fa-search"> </i>
</div>
Optimum Creative
  • 1,438
  • 13
  • 21
0

It is not showing because ::after and ::before[pseudo-elements] works only when they are defined in containing elements. read W3C specifications