Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place icon inside submit button using Bootstrap 3

I am trying to achieve the effect as shown in below screenshot using Bootstrap 3.

enter image description here

As you can see, the search button is both:

1) inside the input

2) styled with a glyphicon so as to not appear like a "button".

How can I achieve a similar effect with Bootstrap 3? I would like to place a button with a magnifying glass glyphicon at the end of a text input, however the button keeps appearing below the input as opposed to inside of it.

like image 300
tdc Avatar asked Jul 27 '14 20:07

tdc


People also ask

How can I add Search icon in submit button?

Answer: Use the CSS position Property However, we can place the Glyphicon outside the input button and push it visually inside to create the effect that looks like the icon is placed inside the button itself using the CSS positioning techniques.

How do you put an icon inside a input field?

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.

How do I add a search icon inside a text box in bootstrap?

Step by step guide for the implementation:Step 1: Include Bootstrap and jQuery CDN into the <head> tag before all other stylesheets to load our CSS. Step 2: Add <div> tag in the HTML body with class container. Step 3: Now add any icon that you want using the below syntax, where the name is the name of glyphicon.

How do you put icons before text in HTML?

To insert an icon, add the name of the icon class to any inline HTML element. The <i> and <span> elements are widely used to add icons. All the icons in the icon libraries below, are scalable vector icons that can be customized with CSS (size, color, shadow, etc.)


1 Answers

A wrapper div with position: relative; then positioning the submit button on top using position: absolute;. Like this:

http://jsfiddle.net/VtP5k/

HTML

<form>

    <div id="search">

        <input type="text" />
        <button type="sutmit">Search</button>

    </div>

</form>

CSS

#search {
    position: relative;
    width: 200px;
}

#search input {
    width: 194px;
}

#search button {
    position: absolute;
    top: 0;
    right: 0;
    margin: 3px 0;
}
like image 75
Niklas Avatar answered Sep 19 '22 02:09

Niklas