How do I add a Font Awesome icon to input field?

前端 未结 8 1709
野性不改
野性不改 2020-11-28 01:36

How do I use the search icon included in Font Awesome for input? I have a search feature on my site (based on PHPmotion), that I want to use for the search.

Here\'s

8条回答
  •  情深已故
    2020-11-28 02:10

    Change your input to a button element and you can use the Font Awesome classes on it. The alignment of the glyph isn't great in the demo, but you get the idea:

    http://tinker.io/802b6/1

    
    
    #search-bar .icon-search {
        width: 30px;
        height: 30px;
        background: black;
        color: white;
        border: none;
        overflow: hidden;
        vertical-align: middle;
        padding: 0;
    }
    
    #search-bar .icon-search:before {
        display: inline-block;
        width: 30px;
        height: 30px;
    }
    

    The advantage here is that the form is still fully functional without having to add event handlers for elements that aren't buttons but look like one.

提交回复
热议问题