adding search icon to input box

后端 未结 3 1066
天涯浪人
天涯浪人 2021-02-04 05:39
3条回答
  •  粉色の甜心
    2021-02-04 06:12

    Here's the CSS code that I'd use:

    #add {
      padding: 17px;
      padding-left: 55px;
      width: 300px;
      border: 1px solid #f5f5f5;
      font-size: 13px;
      color: gray;
      background-image: url('http://i47.tinypic.com/r02vbq.png');
      background-repeat: no-repeat;
      background-position: left center;
      outline: 0;
    }
    

    Note: I added a lot of extra codes to make the search box look better, the necessary code to make the search box apear is padding-left, background-image:url, background-repeat and background-position. Replace "http://i47.tinypic.com/r02vbq.png" with whatever search icon you want.

    It's also important to know that now in HTML5, most browsers render

    
    

    with a search icon. The input type search makes it a search box, with a "x" button to clear, and adding "results" also displays a search box. Of course you could also add an x button with CSS and JavaScript to a regular search box. It's also important to note that input type search allows very little styling. Demo on Safari on a Mac:

    Demo

    Tell me if this helps you, and make sure to mark as the answer. :)

提交回复
热议问题