Put icon inside input element in a form

前端 未结 17 1752
旧时难觅i
旧时难觅i 2020-11-22 16:10

How do I put an icon inside a form\'s input element?

\"Screenshot

17条回答
  •  借酒劲吻你
    2020-11-22 16:29

    I had situation like this. It didn't work because of background: #ebebeb;. I wanted to put background on the input field and that property was constantly showing up on the top of the background image, and i couldn't see the image! So, I moved the background property to be above the background-image property and it worked.

    input[type='text'] {
        border: 0;
        background-image: url('../img/search.png');
        background-position: 9px 20px;
        background-repeat: no-repeat;
        text-align: center;
        padding: 14px;
        background: #ebebeb;
    }
    

    Solution for my case was:

    input[type='text'] {
        border: 0;
        background: #ebebeb;
        background-image: url('../img/search.png');
        background-position: 9px 20px;
        background-repeat: no-repeat;
        text-align: center;
        padding: 14px;
    }
    

    Just to mention, border, padding and text-align properties are not important for the solution. I just replicated my original code.

提交回复
热议问题