How to put an Icone/Lookup Button inside an input with Bootstrap?

Asked

Viewed 3,203 times

2

<form class="form-inline my-2 my-lg-0 pl-3-lg">

    <input class="form-control" type="search" placeholder="Pesquisar" aria-label="Search">
    <button class="btn btn-dark ml-1" type="submit">
      <img src="img/searchIcon.png">
    </button>

</form>
Instead of a button next to the input, I wanted it to be a search icon inside the input, using bootstrap, how do I do this?

Example:

inserir a descrição da imagem aqui

  • 1

    Puts a input-group-prepend. Documentation link: https://getbootstrap.com/docs/4.1/components/forms/

1 answer

6


This would be an option, but you will have to do in "Save" the style, so that the search icon is in the color of the <input>:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">

<div class="col-sm-3 my-1">
  <div class="input-group">
    <input class="form-control" type="search" placeholder="Pesquisar" aria-label="Search" style="border-right: none;">
    <div class="input-group-append">
      <div class="input-group-text" style="background-color: #FFF"><i class="fas fa-search"></i></div>
    </div>
  </div>
</div>

  • Vlw! I forgot to ask one thing. You know when the person clicks the mouse inside the input and the border turns blue?! So, do you know how to change this color? I’ve searched the Bootstrap css and couldn’t find how to change the color.

  • 1

    To remove the Focus, you can use: input[type="search"]:focus{border-color: #ced4da;&#xA; box-shadow: 0 0 0 0;&#xA; outline: 0;}, if you want to change the color use: input[type="search"]:focus{ &#xA; border-color: #28a745;&#xA; box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25);}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.