Html 搜索框内的搜索图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17670865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:12:29  来源:igfitidea点击:

search icon inside search box

htmlcsstwitter-bootstrap

提问by neknek mouh

So what I have right now is this:

所以我现在拥有的是:

SAMPLE

样本

But I want to include icon-search ICON SEARCHinside the textbox on the left side.

但我想在左侧的文本框中包含 icon-search ICON SEARCH

This is my code:

这是我的代码:

<form class="navbar-form pull-left form-search">
    <select>
        <option>Search patient by...</option>
        <option name="fname">Firstname</option>
        <option name="fname">Lastname</option>
        <option name="fname">Last follow up</option>
    </select>
    <div class="input-append">
        <input data-provide="typeahead" data-items="4"  type="text" 
           class="span2 search-query">
        <button class="btn">Search</button>
    </div>
</form>

So any ideas how to achieve this? Thanks.

那么任何想法如何实现这一目标?谢谢。

采纳答案by Ritabrata Gautam

Check this Fiddle

检查这个小提琴

<form class="navbar-form pull-left form-search">
  <div class="input-append">
    <input data-provide="typeahead" data-items="4"  type="text" class="span2 search-query" style="background:url(http://twitter.github.io/bootstrap/assets/img/glyphicons-halflings.png) no-repeat -38px 9px">
    <button class="btn">Search</button>
  </div>
</form>

As you can see there are other icons also showing. You have to use separate "search image" for your textbox.

如您所见,还显示了其他图标。您必须为文本框使用单独的“搜索图像”。

回答by Ritabrata Gautam

<input data-provide="typeahead" data-items="4"  type="text" class="search-query">

.search-query{
   background: url(../images/your_pic.format) no-repeat left ;
}

Just add that image as background aligned left with no-repeat

只需将该图像添加为背景,左对齐,不重复

回答by Chtiwi Malek

you can do something like :

您可以执行以下操作:

HTML :

HTML :

<form class="navbar-form pull-left form-search">
<div class="input-append">
  <i class="icon-zoom-in"></i>
        <input data-provide="typeahead" data-items="4"  type="text" 
           class="span2 search-query">
        <button class="btn">Search</button>
    </div>
  </form>

CSS :

CSS :

.icon-zoom-in
{
  position:relative;
  left:20px;
  top:-8px;
  z-index:999;
}

try it : http://refork.com/xb70

试试看:http: //refork.com/xb70