在文本框内搜索图标

时间:2017-04-24 10:14:55

标签: html twitter-bootstrap

如何在文本框中放置搜索图标

 <input class="col-lg-3 col-md-3 col-sm-5 col-xs-5 form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName"/><span class="fa fa-search form-control-feedback"></span>

工作fiddle

6 个答案:

答案 0 :(得分:2)

希望此代码段能为您提供帮助。

    <div class="col-lg-3 col-md-3 col-sm-5 col-xs-5">    
      <div class="input-group">
                <input type="text" class="form-control" id="exampleInputAmount" placeholder="Amount">
                <div class="input-group-btn">
                    <button type="button" class="btn btn-default">
                         <span class="glyphicon glyphicon glyphicon-search"></span>
                    </button>
                </div>
      </div>
    </div>

答案 1 :(得分:1)

<强> CSS:

input {
  border: 0;
  background: transparent;
  -webkit-appearance: none;
  -moz-appearance: none;
  -ms-appearance: none;
  -o-appearance: none;
  appearance: none;
}
input:focus{
  outline: 0;
}
.input-placeholder{
  background-color: #eee;
  display: inline-block;
  padding: 10px;



}

<强> HTML:

 <div class="input-placeholder">
    <input class="col-lg-3 col-md-3 col-sm-5 col-xs-5 form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName"/><span class="fa fa-search form-control-feedback"></span>
 </div>

这是小提琴https://jsfiddle.net/6d463wo1/1/

答案 2 :(得分:1)

根据您的代码,您似乎正在使用Bootstrap,在bootstrap中它提供了另一种方法,例如input-group。您可以使用以下HTML代码

<div class="col-lg-3 col-md-3 col-sm-5 col-xs-5">
    <div class="input-group">
        <input class="form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName"/><div class="input-group-addon"><span class="fa fa-search form-control-feedback"></span></div>
    </div>
</div>

答案 3 :(得分:1)

这有一种引导方式。使用.input-group-addon类。

<div class="input-group">
  <input type="text" class="form-control" placeholder="Search By RoleName" aria-describedby="basic-addon2">
  <span class="input-group-addon fa fa-search" id="basic-addon2"></span>
</div>

为了将按钮与输入字段内联,请添加此css:

.input-group .fa-search{
  display: table-cell;
}

请在小提琴here

中试一试

答案 4 :(得分:0)

如果需要,可以使用

 <input class="col-lg-3 col-md-3 col-sm-5 col-xs-5 form-control" type="text" name="searchroleName" id="searchroleName" placeholder="Search By RoleName &#128269;"/>

答案 5 :(得分:0)

    <!DOCTYPE ht`enter code here`ml>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" 
   href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/4.7.0/css/font-awesome.min.css">
    <style>

    * {
        box-sizing: border-box;
    }

    .club input[type=text] {
        padding: 10px;
        font-size: 17px;
        border: 1px solid black;
        border-right: 0px solid black;
        float: left;
        width: 90%;
    }

    .club button {
        float: left;
        width: 10%;
        padding: 10px;
        background:white;
        color: black;
        font-size: 17px;
        border: 1px solid grey;
        border-left: none;
        cursor: pointer;
    }

    </style>
    </head>
    <body>

    <div class="club">
      <input type="text" placeholder="Search.." name="search2">
      <button type="submit"><i class="fa fa-search"></i></button>
    <div>

    </body>
    </html> 

code on fiddle