Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can add a button inside an input box using bootstrap

I am trying to find a way to enter a button inside input field as follow:-

enter image description here

can anyone advice ?

like image 445
John John Avatar asked Jan 26 '23 01:01

John John


2 Answers

There is no native bootstrap solutions. You can do this with custom code.

.custom-search {
  position: relative;
  width: 300px;
}
.custom-search-input {
  width: 100%;
  border: 1px solid #ccc;
  border-radius: 100px;
  padding: 10px 100px 10px 20px; 
  line-height: 1;
  box-sizing: border-box;
  outline: none;
}
.custom-search-botton {
  position: absolute;
  right: 3px; 
  top: 3px;
  bottom: 3px;
  border: 0;
  background: #d1095e;
  color: #fff;
  outline: none;
  margin: 0;
  padding: 0 10px;
  border-radius: 100px;
  z-index: 2;
}
<div class="custom-search">
  <input type="text" class="custom-search-input" placeholder="Enter your email">
  <button class="custom-search-botton" type="submit">Subscribe</button>  
</div>

Bootstrap mixed solution, according to bootstrap styles.

   .custom-search {
      position: relative;
    }
    .custom-search-input {
      width: 100%;
      padding-right: 100px !important; 
      box-sizing: border-box;
    }
    .custom-search-botton {
      position: absolute;
      right: 3px; 
      top: 3px;
      bottom: 3px;
      line-height: 1 !important;
      z-index: 4;
    }
 <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script> 
 
 <div class="input-group custom-search">
   <input type="text" class="form-control custom-search-input" placeholder="Enter your email">
   <button class="btn btn-primary custom-search-botton" type="submit">Subscribe</button>  
 </div>
like image 92
focus.style Avatar answered Jan 27 '23 15:01

focus.style


You cant put a button inside a input field with bootstrap only but you can use custom css to move the button inside the input field. I created a small example for you (I used bootstrap 4):

input[type="text"] {
    width: 200px;
    height: 50px;
    padding-right: 50px;
}

.example {
    margin: 5px -90px 5px;
    height: 40px;
    width: 80px;
    z-index: 100;
}

.test-div {
    width: 200px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="test-div">
    <div class="input-group">
       <input type="text" class="form-control" placeholder="Search for...">
       <button class="btn btn-outline-secondary example" type="button">Button</button>
    </div>
</div>
like image 23
ロバート Avatar answered Jan 27 '23 14:01

ロバート