Bootstrap button inside input-group

Bootstrap 4 provides the classes input-group-prepend and input-group-append that allows the effect of button inside input.

Below the snippet for a left aligned button inside input-group (class input-group-prepend):

@import "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css";
<div class="input-group">
  <div class="input-group-prepend">
    <button class="btn btn-outline-secondary" type="button">Prepended button</button>
  </div>
  <input type="text" class="form-control">  
</div>

And the snippet for a right aligned button inside input-group (class input-group-append):

@import "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css";
<div class="input-group">
  <input type="text" class="form-control">  
  <div class="input-group-append">
    <button class="btn btn-outline-secondary" type="button">Button</button>
  </div>
</div>

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>

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(); });


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;
}