Put search icon near textbox using bootstrap

前端 未结 5 1793
清酒与你
清酒与你 2020-12-02 08:51

I am using bootstrap by default textbox taking full width of column and I want to put search icon at the end to textbox.

My code is like this:



        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 09:15

    Here are three different ways to do it:

    Here's a working Demo in Fiddle Of All Three

    Validation:

    You can use native bootstrap validation states (No Custom CSS!):

    For a full discussion, see my answer to Add a Bootstrap Glyphicon to Input Box

    Input Group:

    You can use the .input-group class like this:

    For a full discussion, see my answer to adding Twitter Bootstrap icon to Input box

    Unstyled Input Group:

    You can still use .input-group for positioning but just override the default styling to make the two elements appear separate.

    Use a normal input group but add the class input-group-unstyled:

    Then change the styling with the following css:

    .input-group.input-group-unstyled input.form-control {
        -webkit-border-radius: 4px;
           -moz-border-radius: 4px;
                border-radius: 4px;
    }
    .input-group-unstyled .input-group-addon {
        border-radius: 4px;
        border: 0px;
        background-color: transparent;
    }
    

    Also, these solutions work for any input size

提交回复
热议问题