0

The closest I can find is:

input[data-icon] {
  padding-left: 25px;
  background: url("https://static.thenounproject.com/png/101791-200.png") no-repeat left;
  background-size: 20px;
} 

Search Button

But this icon will be removed once the JQuery's validation icon appears.

I knew Bootstrap input group can prepend and append icons, but those icons had already been reserved for other usage (in my project).

Besides, I wish the added icon is clickable as well. Added as a background image doesn't work.

1
  • @Cervuscamelopardalis, I already have an image in my original question, I need to add an icon button (in the image above, is the magnifying icon, but not limited to that in production) Commented Apr 27, 2022 at 1:45

1 Answer 1

1

Here you go...

This is exactly what you want. The icon is also clickable. See the snippet below.

function myFunction() {
  alert("I am clickable!");
}
.input-icon:hover {
  cursor: pointer;
}
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-skAcpIdS7UcVUC05LJ9Dxay8AXcDYfBJqt1CJ85S/CFujBsIzCIv+l9liuYLaMQ/" crossorigin="anonymous"></script>
  <script src="https://use.fontawesome.com/releases/v5.15.3/js/all.js" data-auto-replace-svg="nest"></script>

</head>

<body>

  <div class="input-group flex-nowrap">
    <span class="input-group-text" id="addon-wrapping">@</span>
    <div class="input-wrapper d-flex align-items-center position-relative">
      <input type="text" class="form-control ps-4" id="my-input" placeholder="E-mail" aria-label="Username" aria-describedby="addon-wrapping">
      <label for="my-input" class="fa fa-user input-icon position-absolute px-2" onclick="myFunction()"></label>
    </div>
  </div>

</body>

</html>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.