【问题标题】:bootstrap - insert glyphicon next to inputbootstrap - 在输入旁边插入字形图标
【发布时间】:2016-04-12 19:45:17
【问题描述】:

我正在尝试在 inout 类型旁边插入一个图标,使用此代码能够做到这一点

<div class="form-group">
    <label for="accountSpan">Account name</label>
        <div class="input-group input-group-unstyled">
            <span class="input-group-addon" id="accountSpan">something</span>
            <input type="text" class="form-control" placeholder="account name" aria-describedby="basic-addon1" id="accountInput">
            <span class="input-group-addon">
                <i class="glyphicon glyphicon-question-sign"></i>
            </span>
       </div>
</div>

还有这个css

            .input-group.input-group-unstyled input.form-control {
                -webkit-border-radius: 4px;
                   -moz-border-radius: 4px;
                        border-radius: 4px;
            }
            .input-group-unstyled .input-group-addon {
                border-radius: 4px;
                border: 0px;
                background-color: transparent;
            }

我在这个帖子Put search icon near textbox using bootstrap中找到的

但是给定的 css 改变了插件的格式,导致

我错过了什么?谢谢

更新

去除背景色:透明;将导致插件有一个边框

【问题讨论】:

  • 尝试删除这个:background-color: transparent;border: 0px;
  • 您能否具体说明您期望的样式。代码在没有这种样式的情况下也可以工作,只需加载 Bootstrap.
  • 感谢您的评论@C0dekid.php,请参阅我的更新。
  • @LionelT 感谢您的回复,我更新了我的 OP :)
  • 你想说什么,你想要带有图标的插件?没有颜色或插件?

标签: css twitter-bootstrap


【解决方案1】:
<div class="col-sm-4 input-group">
   <input class="form-control">
   <span class="input-group-btn">
    <button  class="btn btn-default"><i class="glyphicon glyphicon-search"></i>
   </button>
   </span>                                                </div>                                

【讨论】:

  • 这是最简单的方法
  • 最简单的方法是@potatopeelings 推荐的方法,但感谢您的意见:)
【解决方案2】:

只需将您的第二个选择器更改为

input-group-unstyled .input-group-addon:last-child {
    ...

小提琴 - https://jsfiddle.net/o1x3ubab/

【讨论】:

  • 谢谢。只是一个快速的问题。语法在做什么?像继承吗? .input-group-unstyled .input-group-addon:last-child {
  • 如果没有:last-child,样式将应用于所有.input-group-addon 元素(即标签和图标)。 :last-child 告诉浏览器仅在元素是其包装器中的最后一个元素时应用样式(即仅适用于图标)
猜你喜欢
  • 2017-09-13
  • 1970-01-01
  • 2022-12-26
  • 1970-01-01
  • 2018-02-26
  • 2011-06-28
  • 1970-01-01
  • 2016-09-03
  • 1970-01-01
相关资源
最近更新 更多