在输入中添加Font Awesome Icon

时间:2016-06-15 13:15:11

标签: html css font-awesome

我尝试使用此问题发布此处发布的可能解决方案,但没有人使用我的代码,这就是我所拥有的

<div class="search">
  <span class="fa fa-user"></span>
  <input placeholder="Username...">
</div>
<div class="search">
   <span class="fa fa-lock"></span>
   <input placeholder="*******">
</div>

CSS

@import url("//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css");
body { margin: 30px; }
.search {
   position: relative;
   color: #aaa;
   font-size: 16px;
}
.search input {
  width: 250px;
  height: 32px;
  background: #fcfcfc;
  border: 1px solid #aaa;
  border-radius: 5px;
  box-shadow: 0 0 3px #ccc, 0 10px 15px #ebebeb inset;
}
.search input { text-indent: 32px;}

我想要占位符前的图标。

Here its the example code

2 个答案:

答案 0 :(得分:1)

试试这个,我只是在你的图标上添加一些css。

.search .fa-user { 
        position: absolute;
        top: 10px;
        left: 10px;
    }

.search .fa-lock { 
        position: absolute;
        top: 10px;
        left: 10px;
    }

Here is your code updated

答案 1 :(得分:1)

<style>
@import url("//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css");
body { margin: 30px; }
.search {
  position: relative;
  color: #aaa;
  font-size: 16px;
}
.search input {
  width: 250px;
  height: 32px;

  background: #fcfcfc;
  border: 1px solid #aaa;
  border-radius: 5px;
  box-shadow: 0 0 3px #ccc, 0 10px 15px #ebebeb inset;
}

.search input { text-indent: 32px;}

.search .fa-user { 
            position: absolute;
            top: 10px;
            left: 10px;
        }
.search .fa-lock { 
            position: absolute;
            top: 10px;
            left: 10px;
        }

</style>
<div class="search">
  <span class="fa fa-user"></span>
  <input placeholder="Username...">
</div>
<div class="search">
  <span class="fa fa-lock"></span>
  <input placeholder="*******">
</div>