html - 我如何使用 Bootstrap 在输入框中添加按钮

标签 html css twitter-bootstrap

我正在尝试找到一种在输入字段中输入按钮的方法,如下所示:-

enter image description here

任何人都可以建议吗?

最佳答案

没有 native Bootstrap 解决方案。您可以使用自定义代码执行此操作。

.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 混合解决方案,根据 bootstrap 样式。

   .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>

关于html - 我如何使用 Bootstrap 在输入框中添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61856781/

相关文章:

javascript - Jquery 函数在错误时间提交

javascript - 将复选框放在 JavaScript 的组合框中

html - TW Bootstrap 缩略图背景颜色

html - 图像下的大空白区域,使用百分比调整大小,以便图像在所有查看平台上填满屏幕

css - 引用多个类、id 或元素时如何应用 css 选择器?

css - 关于 robot-or-not.com 代码的几个 CSS 问题

javascript - 使用 JS 循环创建 Bootstrap 网格

css - 将 Bootstrap 品牌定位在导航栏旁边

html - Css 设置左固定和右流体布局

javascript - 如何使用动画在两个 html div 之间定期切换