Editing input type=“search” Pseudo-element Button ('x')

后端 未结 5 920
攒了一身酷
攒了一身酷 2020-12-05 03:46

I\'m trying to make a search bar that will look nice. What I did is, I made an image of an search bar and I\'m adding the image to the back-ground of the input and I\'m edit

5条回答
  •  粉色の甜心
    2020-12-05 04:44

    Styling the "x" cancel search button in Webkit browsers

    Assuming you're talking about "Cancel search" [X] icon that appeas in Webkit browsers only (Chrome, Safari, Opera) you can use -webkit-search-cancel-button pseudo-element. E.g:

    #Search::-webkit-search-cancel-button{
        position:relative;
        right:20px;    
    }
    

    Demo: http://jsfiddle.net/5XKrc/1/

    Screenshot:

    Using this approach you can even create your own cancel button, for example this style:

    #Search::-webkit-search-cancel-button{
        position:relative;
        right:20px;  
    
        -webkit-appearance: none;
        height: 20px;
        width: 20px;
        border-radius:10px;
        background: red;
    }
    

    Instead of [X] will create a red circle.

    Demo http://jsfiddle.net/5XKrc/3/

    Screenshot:

    For IE10 and above you can use following to move the button:

    #Search::-ms-clear{
       margin-right:20px
    }
    

    Oh and do use placeholder="Search" instead of value="Search" - it will display word "search" when input is empty - and will automatically remove it when user types something.

提交回复
热议问题