Bootstrap button inside input-group

2020-05-31 17:01发布

How to make it so that it appears nicely after input page with same height?

<div class="input-group">
        <input type="text" class="form-control"/>
        <button class="input-group-addon" type="submit">
            <i class="fa fa-search"></i>
        </button>
</div>

Here is code http://jsfiddle.net/6mcxdjdr/ The first one is original input-group, the second one is something what I am trying to have

5条回答
一纸荒年 Trace。
2楼-- · 2020-05-31 17:09

Try this,

.input-group-addon{
width:50px;  
position:absolute;
margin-left:196px;
height:34px;
}
.input-group-addon > i{
  text-align:center;
  font-size:18px;
}
查看更多
做自己的国王
3楼-- · 2020-05-31 17:17

here is my solution, using a little CSS to position the button to the right of the input field by adding position: absolute and a z-index:

button.input-group-addon {
  position: absolute;
  right: -38px;
  top: 0;
  padding: 2px;
  z-index: 999;
  height: 34px;
  width: 38px;
}

http://jsfiddle.net/6mcxdjdr/1/

Another idea is to manipulate the form submit with javascript, so you dont have to create your own button but submit the form by clicking on the bootstrap span. This could be done by $('.input-group-addon').click(function(){ $('#myform').submit(); });

查看更多
该账号已被封号
4楼-- · 2020-05-31 17:18

You can also try this way

 <div class="input-group">
          <input type="text" class="form-control search-input" />
          <span class="input-group-addon">
            <i class="fa fa-search"></i>
          </span><span class="input-group-addon">
            <i class="fa fa-refresh"></i>
          </span>
        </div>

.search-input {
  border-right: 0;
}

.input-group-addon {
  background: white;
  border-left: 0;
  border-right: 0;
}

.input-group-addon:last-child {
  border-left: 0;
  border-right: 1px solid #ccc;
}
查看更多
ゆ 、 Hurt°
5楼-- · 2020-05-31 17:24

Here's how I did it, I had to override some css...

(Bootstrap 4 Beta 2)

Html

    <div class="input-group">
        <input type="search" class="form-control" placeholder="search..." />
        <span class="input-group-addon input-group-addon-btn bg-white">
            <button class="btn px-2" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button>
        </span>
    </div>

And here's the css

#app-search .input-group-addon-btn {
    padding: 0;

    button {
        border: none;
        background: transparent;
        cursor: pointer;
        height: 100%;
    }
}
查看更多
萌系小妹纸
6楼-- · 2020-05-31 17:25

If you follow bootstrap's documentation:

<div class="input-group">
  <input type="text" class="form-control" placeholder="Search for...">
  <span class="input-group-btn">
    <button class="btn btn-default" type="submit">
        <i class="fa fa-search"></i>
    </button>
  </span>
</div>
查看更多
登录 后发表回答