【问题标题】:Bootstrap Input Group with Image带图像的引导输入组
【发布时间】:2018-11-16 16:54:22
【问题描述】:

我正在使用 bootstrap 3 创建带有普通文本的输入组,如下图所示

如何获得带有图像和超过 2 个跨度文本的输入组。

我将以下代码用于普通输入组

<div class="input-group input-group-lg">
  <input type="text" style="background-color: black; color: white" class="form-control" aria-label="You Send">
  <div class="input-group-btn">
    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span></button>
    <ul class="dropdown-menu dropdown-menu-right">
      <li><a href="#">Action</a></li>
      <li><a href="#">Another action</a></li>
      <li><a href="#">Something else here</a></li>
      <li role="separator" class="divider"></li>
      <li><a href="#">Separated link</a></li>
    </ul>
  </div>
  <!-- /btn-group -->
</div>
<!-- /input-group -->

编辑 1:

【问题讨论】:

  • 你能解释一下你所说的两跨文本是什么意思吗?你说的是下拉搜索建议吗?

标签: html css twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

有许多 CSS 技巧可以在输入字段中嵌入图像。就我个人而言,如果我们要使用 Bootstrap,让我们真正使用 Bootstrap。也许还有一个像 FontAwesome 这样的图标包。

.search-icon:before {
  font: normal normal normal 14px/1 FontAwesome;
  content: "\f002";
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<div class="input-group">
  <div class="input-group-prepend">
    <span class="input-group-text border-right-0 bg-white">
    <!-- Stack overflow doesn't allow this, but if it did, I would not need
         any custom  css, just the following html only this: 
    <i class="fas fa-search"></i>
    Instead I have to use this over here. -->
      <span class="search-icon"></span>
    </span>
  </div>
  <input type="text" class="form-control border-left-0" placeholder="Search">
</div>

如果您想放置自己的自定义图像,您可以像这样编辑 css:

.search-icon:before {
  content: url(path/to/your-image.jpg);
}

一旦你澄清了两段文字的意思,我会更新我的答案。

【讨论】:

  • 嗨,请检查我添加了新图片,我正在寻找这样的 2 个文本类型。
  • @DivyamSolanki 值得提出自己的问题,因为它相当复杂。但是,我强烈推荐 typeahead.js。这相当简单,并且在 stackoverflow 上有足够的关于该主题的问题和答案。 twitter.github.io/typeahead.js/examples
  • 谢谢。示例很有帮助。
猜你喜欢
  • 2017-02-26
  • 2013-02-09
  • 2014-06-24
  • 2014-11-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多