With the latest Bootstrap 4
, I am trying to put an x in a search input
.
I could simply use
<input type="search" placeholder="Search..." />
But this is not supported in Firefox
...
I've tried using addon
and negative margins
, but somehow the Bootstrap hides my button...
<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>
How can I have my x button show up inside the input box aligned right?
Bootstrap 5 Search component The search box is an UI element prepared for creating search engines. Its most important element is search input, but it can also contain icons or buttons. It is also adjusted to be used in various other components such as navbar, dropdown, table, select, sidenav and many more.
That works in at least Chrome 8, Edge 14, IE 10, and Safari 5 and does not require Bootstrap or any other library. (Unfortunately, it seems Firefox does not support the search clear button yet.) After typing in the search box, an 'x' will appear which can be clicked to clear the text.
Bootstrap 3 resets a lot of CSS and breaks the HTML 5 search cancel button. After the Bootstrap 3 CSS has been loaded, you can restore the search cancel button with the CSS used in the following example:
That works in at least Chrome 8, Edge 14, IE 10, and Safari 5 and does not require Bootstrap or any other library. (Unfortunately, it seems Firefox does not support the search clear button yet.)
I think that input-group-addon
is the problem.
Try this:
<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>
This looks like this:
There's an example in the Bootstrap documentation that you could adapt:
https://getbootstrap.com/docs/4.1/components/input-group/#button-addons
e.g.
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With