在最新的Bootstrap 4中,我尝试在search input中添加一个x。
我可以简单地使用
<input type="search" placeholder="Search..." />但这在Firefox中不受支持...
我试过使用addon和negative 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>我怎样才能让我的x按钮在输入框中正确对齐?
发布于 2018-10-19 22:22:21
我认为input-group-addon才是问题所在。
试试这个:
<div class="input-group">
<input type="text" class="form-control" placeholder="Search...">
<button type="button" class="btn bg-transparent" style="margin-left: -40px; z-index: 100;">
<i class="fa fa-times"></i>
</button>
</div>这看起来像这样:

发布于 2018-10-19 22:21:06
它将与methods explained here相同。
使用输入组并调整边框。
<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>使用按钮上的相对位置...
<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;
}使用包含列的行并调整边框。
<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>发布于 2018-10-19 22:21:42
Bootstrap文档中有一个示例,您可以对其进行调整:
https://getbootstrap.com/docs/4.1/components/input-group/#button-addons
例如:
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="button-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="button-addon2">X</button>
</div>
</div>https://stackoverflow.com/questions/52894166
复制相似问题