How can we add a Twitter Bootstrap icon icon-search
to the right of a text input element?
The following attempt placed all the icons inside the input element, how can we crop it so it only displays the icon for icon-search
?
Current Attempt
CSS
input.search-box { width: 180px; background: #333; background-image: url('/img/glyphicons-halflings-white.png'); background-position: -48px 0; padding-left: 30px; margin-top: 45px; border: 0; float: right; }
To add icon inside the input element the <i> tag and <span> tag are used widely to add icons on the webpages. To add any icons on the webpages or in some specific area, it needs the fontawesome link inside the head tag. The fontawesome icon can be placed by using the fa prefix before the icon's name.
You can use the .input-group
class like this:
<div class="input-group"> <input type="text" class="form-control"/> <span class="input-group-addon"> <i class="fa fa-search"></i> </span> </div>
You can use the .input-append
class like this:
<div class="input-append"> <input class="span2" type="text"> <button type="submit" class="btn"> <i class="icon-search"></i> </button> </div>
Both will look like this:
If you'd like the icon inside the input box, like this:
Then see my answer to Add a Bootstrap Glyphicon to Input Box
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