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

前端 未结 8 1719
野性不改
野性不改 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:04

    Here is a solution that works with simple CSS and standard font awesome syntax, no need for unicode values, etc.

    1. Create an tag followed by a standard tag with the icon you need.

    2. Use relative positioning together with a higher layer order (z-index) and move the icon over and on top of the input field.

    3. (Optional) You can make the icon active, to perhaps submit the data, via standard JS.

    See the three code snippets below for the HTML / CSS / JS.

    Or the same in JSFiddle here: Example: http://jsfiddle.net/ethanpil/ws1g27y3/

    $('#filtersubmit').click(function() {
      alert('Searching for ' + $('#filter').val());
    });
    #filtersubmit {
      position: relative;
      z-index: 1;
      left: -25px;
      top: 1px;
      color: #7B7B7B;
      cursor: pointer;
      width: 0;
    }
    
    
    
    
    

提交回复
热议问题