Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4: search input x clear search [duplicate]

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?

like image 767
Thibs Avatar asked Oct 19 '18 14:10

Thibs


People also ask

What is search box in Bootstrap 5?

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.

Is there a way to search and clear text without bootstrap?

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.

How to restore the search Cancel button in Bootstrap 3?

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:

Which browsers support the search clear button?

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


2 Answers

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:

enter image description here

like image 142
Tommy Avatar answered Oct 11 '22 14:10

Tommy


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>
like image 34
David Lavender Avatar answered Oct 11 '22 14:10

David Lavender