简体   繁体   English

在输入中添加Font Awesome Icon

[英]Add Font Awesome Icon inside input

I try the possible solutions posted here with this problem but no one works with my code, this is what I have 我尝试使用此问题发布在此处的可能解决方案,但没有人使用我的代码,这就是我所拥有的

<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 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;}

I want the icon before the placeholder. 我想要占位符之前的图标。

Here its the example code 这是它的示例代码

Try this, I just add some css to your icons. 试试这个,我只是给你的图标添加一些CSS。

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

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

Here is your code updated 这是您的代码更新

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM