How to add search and mic button in input text? - html

I want to add a search icon on the left side of the input text and a speaker icon on the right side.
Something like this
Currently my I have :
Here is my code :
.search-bar {
width: 20%;
position: relative;
}
.search-bar input {
width: 100%;
height: 30px;
text-align: center;
border: none;
border-radius: 18px;
outline: none;
}
.search-ico {
position: absolute;
left: 10px;
}
<!--Search Bar-->
<div class="search-bar">
<input type="text" name="search" placeholder="Search" />
<i class="fa-solid fa-magnifying-glass search-ico"></i>
</div>
How can I achieve this? Thanks.

In addition to the answer above you can add pointer for the icon for simulate mouse with cursor:pointer; like:
body {
background: #333;
marging: 0;
}
.search-bar {
width: 30%;
position: relative;
}
.search-bar input {
width: calc(100% - 60px);
height: 30px;
text-align: center;
border: none;
border-radius: 18px;
outline: none;
padding: 0 30px;
}
.search-ico {
position: absolute;
left: 10px;
top:8px;
cursor: pointer; // add cursor
}
.microphone-ico {
position: absolute;
right: 10px;
top: 8px;
cursor: pointer; // add cursor
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!--Search Bar-->
<div class="search-bar">
<input type="text" name="search" placeholder="Search" />
<i class="fa fa-search search-ico"></i>
<i class="fa fa-microphone microphone-ico"></i>
</div>
If you use bootstrap 4 you can use input group like:
.input-group-text i{
cursor:pointer;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-search search-ico"></i></span>
</div>
<input type="text" class="form-control" aria-label="Search here">
<div class="input-group-append">
<span class="input-group-text"><i class="fa fa-microphone microphone-ico"></i></span>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

You are going the right way, using position: absolute set the icons
body {
background: #333;
marging: 0;
}
.search-bar {
width: 30%;
position: relative;
}
.search-bar input {
width: calc(100% - 60px);
height: 30px;
text-align: center;
border: none;
border-radius: 18px;
outline: none;
padding: 0 30px;
}
.search-ico {
position: absolute;
left: 10px;
top:8px;
}
.microphone-ico {
position: absolute;
right: 10px;
top: 8px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!--Search Bar-->
<div class="search-bar">
<input type="text" name="search" placeholder="Search" />
<i class="fa fa-search search-ico"></i>
<i class="fa fa-microphone microphone-ico"></i>
</div>

Related

making form with buttons inline

I have 2 buttons and a form with input type inside of it. I want all of them be inline , but I can't do that.
This is what I have:
.btn-registerLayout {
background-color: #425fab;
font-size: 10px;
outline: none;
text-align: left;
cursor: pointer;
height: 22px !important;
width: 50px !important;
padding: 0 !important;
margin: 0 !important;
}
.btn {
color: #fff !important;
}
/* Search Section*/
.header-search .header-search-box {
position: relative;
width: 100%;
}
.header-search-input {
width: 100%;
background: #f0f0f0;
font-size: 12px;
height: 20px;
transition: .2s;
color: darkgreen;
outline: none;
display: inline;
border: 1px solid red !important;
position: relative;
overflow: hidden;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="d-inline pl-5" style="float:left">
<div class="d-inline">
<form asp-action="Index" asp-controller="Products" class="form-inline" method="get">
<input type="search" class="header-search-input" name="SearchKey" placeholder="Search">
</form>
</div>
<button class="btn btn-registerLayout d-inline" style="width:28px !important">
<i class="ml-2 bi bi-person-plus-fill"></i>
</button>
<button class="btn btn-registerLayout d-inline">
<i class="ml-2 bi bi-box-arrow-in-right"></i><span style="padding-left:5px"> Login</span>
</button>
</div>
but I can not make form inline with buttons and result is like this:
Add d-inline-flex on the parent to get the elements inline, then you can use spacers or ml to space out the buttons from the input.
.btn-registerLayout {
background-color: #425fab;
font-size: 10px;
outline: none;
text-align: left;
cursor: pointer;
height: 22px !important;
width: 50px !important;
padding: 0 !important;
margin: 0 !important;
}
.btn {
color: #fff !important;
}
/* Search Section*/
.header-search .header-search-box {
position: relative;
width: 100%;
}
.header-search-input {
width: 100%;
background: #f0f0f0;
font-size: 12px;
height: 20px;
transition: .2s;
color: darkgreen;
outline: none;
display: inline;
border: 1px solid red !important;
position: relative;
overflow: hidden;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="d-inline-flex pl-5">
<div class="d-inline-block mx-auto">
<form asp-action="Index" asp-controller="Products" class="form-inline" method="get">
<input type="search" class="header-search-input" name="SearchKey" placeholder="Search">
</form>
</div>
<button class="btn btn-registerLayout d-inline ml-2" style="width:28px !important">
<i class="bi bi-person-plus-fill"></i>
</button>
<button class="btn btn-registerLayout d-inline ml-2">
<i class="bi bi-box-arrow-in-right"></i><span> Login</span>
</button>
</div>
.btn-registerLayout {
background-color: #425fab;
font-size: 10px;
cursor: pointer;
}
.btn {
color: #fff !important;
}
/* Search Section*/
.header-search .header-search-box {
position: relative;
width: 100%;
}
.header-search-input {
width: 100%;
background: #f0f0f0;
font-size: 12px;
height: 20px;
transition: .2s;
color: darkgreen;
outline: none;
display: inline;
border: 1px solid red !important;
position: relative;
overflow: hidden;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.8.1/font/bootstrap-icons.css">
<div class="d-inline pl-5" style="float:left">
<div class="d-inline">
<form asp-action="Index" asp-controller="Products" class="form-inline" method="get">
<input type="search" class="header-search-input" name="SearchKey" placeholder="Search">
</form>
</div>
<div class="btn-wrap"><button class="btn btn-registerLayout d-inline">
<span>Login<i class="ml-2 bi bi-box-arrow-in-right"></i></span>
</button>
<button class="btn btn-registerLayout d-inline">
<i class="ml-1 bi bi-person-plus-fill"></i>
</button>
</div>
</div>
</div>
Always works a bit better grouping buttons like that in a wrapper of some sort.

How i can add a button inside an input box using bootstrap

I am trying to find a way to enter a button inside input field as follow:-
can anyone advice ?
There is no native bootstrap solutions. You can do this with custom code.
.custom-search {
position: relative;
width: 300px;
}
.custom-search-input {
width: 100%;
border: 1px solid #ccc;
border-radius: 100px;
padding: 10px 100px 10px 20px;
line-height: 1;
box-sizing: border-box;
outline: none;
}
.custom-search-botton {
position: absolute;
right: 3px;
top: 3px;
bottom: 3px;
border: 0;
background: #d1095e;
color: #fff;
outline: none;
margin: 0;
padding: 0 10px;
border-radius: 100px;
z-index: 2;
}
<div class="custom-search">
<input type="text" class="custom-search-input" placeholder="Enter your email">
<button class="custom-search-botton" type="submit">Subscribe</button>
</div>
Bootstrap mixed solution, according to bootstrap styles.
.custom-search {
position: relative;
}
.custom-search-input {
width: 100%;
padding-right: 100px !important;
box-sizing: border-box;
}
.custom-search-botton {
position: absolute;
right: 3px;
top: 3px;
bottom: 3px;
line-height: 1 !important;
z-index: 4;
}
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<div class="input-group custom-search">
<input type="text" class="form-control custom-search-input" placeholder="Enter your email">
<button class="btn btn-primary custom-search-botton" type="submit">Subscribe</button>
</div>
You cant put a button inside a input field with bootstrap only but you can use custom css to move the button inside the input field. I created a small example for you (I used bootstrap 4):
input[type="text"] {
width: 200px;
height: 50px;
padding-right: 50px;
}
.example {
margin: 5px -90px 5px;
height: 40px;
width: 80px;
z-index: 100;
}
.test-div {
width: 200px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="test-div">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<button class="btn btn-outline-secondary example" type="button">Button</button>
</div>
</div>
I changed your source and use font awesome. I think it became more nice, isn't it?
.custom-search {
position: relative;
}
.custom-search-input {
width: 100%;
padding-right: 100px !important;
box-sizing: border-box;
}
.custom-search-botton {
position: absolute;
right: 35px;
top: 1px;
bottom: 3px;
line-height: 1 !important;
z-index: 4;
border: none;
border-radius: 50px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" integrity="sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9"
crossorigin="anonymous">
<div class="input-group custom-search" >
<input type="text" (keyup.enter)="onSearch()" class="form-control custom-search-input" placeholder="Search" aria-label="Search">
<i class="btn fas fa-search custom-search-botton" type="button"></i>
</div>

How to make boostrap button full width?

I have trouble making my button full width in the form.
Also I want the button to be aligned with the forms bottom, so it takes 100% of white space in width and in the bottom.
I suppose Im having some sort of trouble with some of the containers so it cant be scaled properly with standard full width options?
body {
font-family: 'Open Sans', sans-serif;
width: 100%;
text-align: center;
margin: 20px 0px 20px 0px;
}
.forma {
margin: 0 auto 0 auto;
max-width: 450px;
width: 450px;
height: 700px;
}
.fa-container {
float: left;
background-color: #0975BB;
width: 10%;
height: calc(1.5em + .75rem + 2px);
position: relative;
}
i {
color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.form-control {
border-radius: 0%;
float: left;
width: 90%;
margin-bottom: 25px;
}
.btn {
border-radius: 0%;
width: 100%;
background-color: #0975BB;
border-style: hidden;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css " integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="js/script.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
<div class="forma shadow p-3 mb-5 bg-white rounded">
<img class="top-logo" src="images/csd.png">
<form>
<div class="form-group">
<div class="fa-container">
<i class="fas fa-key"></i>
</div>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Šifra">
</div>
<div class="form-group">
<div class="fa-container">
<i class="fas fa-lock"></i>
</div>
<input type="password" class="form-control btn-block" id="exampleInputPassword1" placeholder="Lozinka">
</div>
<button type="button" class="btn btn-primary ">Sign In</button>
</form>
</div>
Bootstrap 4 has a class pre-defined for this add "btn-block" to the button class
btn-block adds the below CSS styles
display: block;
width: 100%;
Below is an example of how to get it close to what you have linked
body {
font-family: 'Open Sans', sans-serif;
width: 100%;
text-align: center;
margin: 20px 0px 20px 0px;
}
.forma {
margin: 0 auto 0 auto;
max-width: 450px;
width: 450px;
height: 300px;
}
.fa-container {
float: left;
background-color: #0975BB;
width: 10%;
height: calc(1.5em + .75rem + 2px);
position: relative;
}
i {
color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.form-control {
border-radius: 0%;
float: left;
width: 90%;
margin-bottom: 25px;
}
.btn {
border-radius: 0%;
width: 100%;
background-color: #0975BB;
border-style: hidden;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<body style="margin-top: 200px;">
<div class="forma shadow mb-5 bg-white rounded">
<img class="top-logo" src="images/csd.png">
<form>
<div class="form-group p-3">
<div class="fa-container">
<i class="fas fa-key"></i>
</div>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp"
placeholder="Šifra">
</div>
<div class="form-group p-3">
<div class="fa-container">
<i class="fas fa-lock"></i>
</div>
<input type="password" class="form-control btn-block" id="exampleInputPassword1" placeholder="Lozinka">
</div>
<button type="button" class="btn btn-primary ">Sign In</button>
</form>
</div>
The CSS should be written in an <style> tag or in a separate file.
The code is working fine. The button if full width too.
Check it out live here: https://codepen.io/manaskhandelwal1/pen/rNVWEEX
EDIT
To do so remove p-3 and mb-5 class from the div with class .forma.
And do not give the form a fixed height.
See here: https://codepen.io/manaskhandelwal1/pen/zYGogBG

How to center the icons using css

I have a mini project here. When I try to text-align: center; in body, the icons don't follow. If I remove the left: 0; in .content-label i in css, it stays on the right and I have no clue how to put it on the left side.
For more info, please check my code.
https://jsfiddle.net/Foxseiz/zse8tuL9/2/
There you go.
Try not to use position absolute as first priority as its the last option to style and element :)
/* CSS files add styling rules to your content */
body {
font-family: verdana, arial, sans-serif !important;
margin: auto;
max-width: 800px;
margin-top: 50px;
text-align: center;
}
input[type="text"] {
width: 180px;
border: 2px solid #aaa;
border-radius: 4px;
margin: 8px 0;
outline: none;
padding: 8px;
box-sizing: border-box;
transition: 0.3s;
}
input[type="text"]:focus {
border-color: dodgerBlue;
box-shadow: 0 0 8px 0 dodgerBlue;
}
.content-label input[type="text"] {
padding-left: 50px;
}
.content-label {
position: relative;
}
.content-label i {
left: 0;
top: 8px;
padding: 9px 8px;
color: #aaa;
transition: 0.3s;
}
.content-label input[type="text"]:focus + i {
color: dodgerBlue;
}
.content-label.inputIconBg i {
background-color: #aaa;
color: #fff;
padding: 9px 8px;
border-radius: 4px 0 0 4px;
line-height: inherit !important;
width: 40px;
text-align: center;
}
.content-label.inputIconBg input[type="text"]:focus + i {
color: #fff;
background-color: dodgerBlue;
}
.content-label {
position: relative;
display: flex;
flex-direction: row-reverse;
margin: 0 auto;
text-align: center;
align-items: center;
justify-content: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link href="/your-path-to-fontawesome/css/fontawesome.css" rel="stylesheet"/>
<link href="/your-path-to-fontawesome/css/brands.css" rel="stylesheet" />
<link href="/your-path-to-fontawesome/css/solid.css" rel="stylesheet" />
<script src="https://kit.fontawesome.com/ed2e310181.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div id="full-content">
<div id="content">
<form autocomplete="off">
<div class="content-label inputIconBg">
<input type="text" id="cost" placeholder="Cost"/>
<i class="fas fa-dollar-sign" data-toggle="tooltip" title="Cost" data-placement="left"></i>
</div>
<div class="content-label inputIconBg">
<input type="text" id="margin" value="1.4" placeholder="Margin"/>
<i class="fas fa-coins" data-toggle="tooltip" title="Margin" data-placement="left"></i>
</div>
<div class="content-label inputIconBg">
<input type="text" id="labor" value="35" placeholder="Labor"/>
<i class="fas fa-hammer" data-toggle="tooltip" title="Labor" data-placement="left"></i>
</div>
<div class="content-label inputIconBg">
<input type="text" id="shipping" value="15" placeholder="Shipping"/>
<i class="fas fa-truck" data-toggle="tooltip" title="Shipping" data-placement="left"></i>
</div>
</form>
<button id="calc" onclick="calculate()">Calculate</button>
</div>
<p id="result"></p>
</div>
</body>
</html>
Use
.content-label.inputIconBg i {
margin-right: -42px;
}
to align icon inside input
You can use Flexbox.
You can set your content-label as flex element and center with justify-content property.
N.B. i used order property because you set the i tag after the input, so i change the order.
/* CSS files add styling rules to your content */
body {
font-family: verdana, arial, sans-serif !important;
margin: auto;
max-width: 800px;
margin-top: 50px;
text-align: center;
}
input[type="text"] {
width: 180px;
border: 2px solid #aaa;
border-radius: 4px;
margin: 8px 0;
outline: none;
padding: 8px;
box-sizing: border-box;
transition: 0.3s;
}
input[type="text"]:focus {
border-color: dodgerBlue;
box-shadow: 0 0 8px 0 dodgerBlue;
}
.content-label input[type="text"] {
padding-left: 50px;
order:2;
}
.content-label {
position: relative;
display:flex; /* add this */
justify-content:center; /* add this */
}
.content-label i {
/*position: absolute;
left: 0;
top: 8px;*/ /* comment this */
margin: 9px 0 8px 8px;
color: #aaa;
transition: 0.3s;
order:1;
}
.content-label input[type="text"]:focus + i {
color: dodgerBlue;
}
.content-label.inputIconBg i {
background-color: #aaa;
color: #fff;
padding: 9px 8px;
border-radius: 4px 0 0 4px;
line-height: inherit !important;
width: 40px;
text-align: center;
}
.content-label.inputIconBg input[type="text"]:focus + i {
color: #fff;
background-color: dodgerBlue;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link href="/your-path-to-fontawesome/css/fontawesome.css" rel="stylesheet"/>
<link href="/your-path-to-fontawesome/css/brands.css" rel="stylesheet" />
<link href="/your-path-to-fontawesome/css/solid.css" rel="stylesheet" />
<script src="https://kit.fontawesome.com/ed2e310181.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div id="full-content">
<div id="content">
<form autocomplete="off">
<div class="content-label inputIconBg">
<input type="text" id="cost" placeholder="Cost"/>
<i class="fas fa-dollar-sign" data-toggle="tooltip" title="Cost" data-placement="left"></i>
</div>
<div class="content-label inputIconBg">
<input type="text" id="margin" value="1.4" placeholder="Margin"/>
<i class="fas fa-coins" data-toggle="tooltip" title="Margin" data-placement="left"></i>
</div>
<div class="content-label inputIconBg">
<input type="text" id="labor" value="35" placeholder="Labor"/>
<i class="fas fa-hammer" data-toggle="tooltip" title="Labor" data-placement="left"></i>
</div>
<div class="content-label inputIconBg">
<input type="text" id="shipping" value="15" placeholder="Shipping"/>
<i class="fas fa-truck" data-toggle="tooltip" title="Shipping" data-placement="left"></i>
</div>
</form>
<button id="calc" onclick="calculate()">Calculate</button>
</div>
<p id="result"></p>
</div>
</body>
</html>

CSS display inline

i'm trying display close icon inside input text. struggling with CSS issue. my code was
<div class="input-group">
<input type="text" class="form-control" />
<i class="fa fa-times-circle ng-hide"></i>
<span class="input-group-btn">
<button type="button" class="btn btn-default">
<span class="fa fa-search"></span> Search
</button>
</span>
</div>
that shows underneath the text box control instead of showing inside the text box could you please help me to fix the css issue
here is the sample plunker
Make the icon position: absolute and position with right and top.
The input-group is already position:relative and the icon will position itself in relation to it.
z-index: 2 places the icon above the text input.
It will now look like this:
or without the input group and button:
Examples
In this example I have placed an additional class (.inside) on the icon element so that it will only apply to specified icons.
With input-group
Note .input-group .inside { right: 100px; }. This ensures that when there is a button (inside the input group), then the close button gets extra space on the right.
.inside {
position: absolute;
top: 10px;
right: 20px;
z-index: 2;
}
.input-group .inside {
right: 100px;
}
<link data-require="bootstrap#*" data-semver="3.2.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
<link data-require="font-awesome#*" data-semver="4.2.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css" />
<script data-require="bootstrap#*" data-semver="3.2.0" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
<script data-require="jquery#*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<input type="text" class="form-control" />
<i class="fa fa-times-circle ng-hide inside"></i>
<span class="input-group-btn">
<button type="button" class="btn btn-default">
<span class="fa fa-search"></span> Search
</button>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
Without input-group
body {
padding-top: 50px; /* ignore this. It is just for this example*/
}
.inside {
position: absolute;
top: 10px;
right: 20px;
z-index: 2;
}
.input-group .inside {
right: 100px;
}
<link data-require="bootstrap#*" data-semver="3.2.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
<link data-require="font-awesome#*" data-semver="4.2.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css" />
<script data-require="bootstrap#*" data-semver="3.2.0" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
<script data-require="jquery#*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<div class="row">
<div class="col-sm-4">
<input type="text" class="form-control" />
<i class="fa fa-times-circle ng-hide inside"></i>
</div>
</div>
</div>
</div>
</div>
Demo
You need to add following css
.fa-times-circle:before {
content:"\f057";
position: absolute;
right: 90px;
z-index: 2;
top: 10px;
}
Add relative position for input-group and than move close icon with position: relative;
.input-group {
position: relative;
}
.close-icon {
position: absolute;
top: 10px;
right: 100px;
z-index: 6;
}
/* Styles go here */
/**********************/
/* prevent text from appearing underneath the icon */
input[reset-field] {
padding-right: 19px;
}
/* hide the built-in IE10+ clear field icon */
input[reset-field]::-ms-clear {
display: none;
}
/* hide cancel icon for search type */
input[reset-field]::-webkit-search-cancel-button {
-webkit-appearance: none;
}
/* icon styles */
input[reset-field] + .fa {
position: absolute;
right: 100px;
top: 10px;
color: #C0C0C0;
cursor: default;
display: inline;
z-index: 9999;
}
/* animations for ngAnimate */
input[reset-field] + .fa.ng-hide-add {
display: inline!important;
-webkit-animation: 0.3s fadeOut;
-moz-animation: 0.3s fadeOut;
-ms-animation: 0.3s fadeOut;
animation: 0.3s fadeOut;
}
input[reset-field] + .fa.ng-hide-remove {
-webkit-animation: 0.5s fadeIn;
-moz-animation: 0.5s fadeIn;
-ms-animation: 0.5s fadeIn;
animation: 0.5s fadeIn;
}
.input-group {
position: relative;
}
.close-icon {
position: absolute;
top: 10px;
right: 100px;
z-index: 6;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link data-require="bootstrap#*" data-semver="3.2.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
<link data-require="font-awesome#*" data-semver="4.2.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css" />
<script data-require="bootstrap#*" data-semver="3.2.0" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<input type="text" class="form-control" />
<i class="fa fa-times-circle ng-hide close-icon"></i>
<span class="input-group-btn">
<button type="button" class="btn btn-default">
<span class="fa fa-search"></span> Search
</button>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
Code Below Will Work For you
There are modification to your code only.
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap#*" data-semver="3.2.0" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css" />
<link data-require="font-awesome#*" data-semver="4.2.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css" />
<script data-require="bootstrap#*" data-semver="3.2.0" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
<script data-require="jquery#*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<div class="row">
<div class="col-sm-4">
<div class="input-group">
<div class="search-wrapper">
<form>
<input type="text" name="focus" required class="search-box" placeholder="Enter search term" />
<button class="close-icon" type="reset"></button>
</form>
</div>
<span class="input-group-btn">
<button type="button" class="btn btn-default">
<span class="fa fa-search"></span> Search
</button>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
body {
background-color: #f1f1f1;
font-family: Helvetica,Arial,Verdana;
}
h1 {
color: green;
text-align: center;
}
.redfamily {
color: red;
}
.search-box,.close-icon,.search-wrapper {
position: relative;
padding: 10px;
}
.search-wrapper {
width: 500px;
margin: auto;
margin-top: 50px;
}
.search-box {
width: 80%;
border: 1px solid #ccc;
outline: 0;
border-radius: 15px;
}
.search-box:focus {
box-shadow: 0 0 15px 5px #b0e0ee;
border: 2px solid #bebede;
}
.close-icon {
border:1px solid transparent;
background-color: transparent;
display: inline-block;
vertical-align: middle;
outline: 0;
cursor: pointer;
}
.close-icon:after {
content: "X";
display: block;
width: 15px;
height: 15px;
position: absolute;
background-color: #FA9595;
z-index:1;
right: 35px;
top: 0;
bottom: 0;
margin: auto;
padding: 2px;
border-radius: 50%;
text-align: center;
color: white;
font-weight: normal;
font-size: 12px;
box-shadow: 0 0 2px #E50F0F;
cursor: pointer;
}
.search-box:not(:valid) ~ .close-icon {
display: none;
}
</style>
</body>
</html>