Bootstrap 4:搜索输入x清除搜索

Thi*_*ibs 3 twitter-bootstrap bootstrap-4

在最新的情况下Bootstrap 4,我试图在x中放一个x search input

我可以简单地使用

<input type="search" placeholder="Search..." />
Run Code Online (Sandbox Code Playgroud)

但这在Firefox...中不受支持

我尝试使用addonnegative margins,但是Bootstrap某种程度上隐藏了我的按钮...

<div class="input-group">
    <input type="text" class="form-control" placeholder="Search...">
        <div class="input-group-addon">
          <button class="btn bg-transparent">
            <i class="fa fa-times"></i>
          </button>
        </div>
</div>
Run Code Online (Sandbox Code Playgroud)

如何使我的x按钮显示在右对齐的输入框中?

Zim*_*Zim 6

这将与此处解释方法相同。

使用输入组并调整边框..

  <div class="input-group">
        <input class="form-control py-2 border-right-0 border" type="search" value="search" id="example-search-input">
        <span class="input-group-append">
            <button class="btn btn-outline-secondary border-left-0 border" type="button">
                <i class="fa fa-times"></i>
            </button>
        </span>
  </div>
Run Code Online (Sandbox Code Playgroud)

使用按钮上的相对位置...

 <div class="d-flex">
     <input class="form-control py-2 bg-transparent" type="search" value="search" id="example-search-input">
     <button class="btn btn-outline-secondary border-0 btn-pos" type="button">
         <i class="fa fa-times"></i>
     </button>
 </div>

 .btn-pos {
    position:relative;
    z-index:1;
    left: -36px;
 }
Run Code Online (Sandbox Code Playgroud)

使用带列的行并调整边框..

  <div class="row no-gutters">
        <div class="col">
            <input class="form-control border-secondary border-right-0 rounded-0" type="search" value="search" id="example-search-input4">
        </div>
        <div class="col-auto">
            <button class="btn btn-outline-secondary border-left-0 rounded-0 rounded-right" type="button">
                <i class="fa fa-times"></i>
            </button>
        </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

https://www.codeply.com/go/SCMW5b1DKr


Tom*_*mmy 6

我认为这input-group-addon就是问题所在。

尝试这个:

<div class="input-group">
    <input type="text" class="form-control" placeholder="Search...">
    <button class="btn bg-transparent" style="margin-left: -40px; z-index: 100;">
      <i class="fa fa-times"></i>
    </button>
</div>
Run Code Online (Sandbox Code Playgroud)

看起来像这样:

在此处输入图片说明