htmlcssbutton

How to add background image for input type="button"?


i've been trying to change the background image of the input button through css, but it doesn't work.

search.html:

<body>
    <form name="myform" class="wrapper">
        <input type="text" name="q" onkeyup="showUser()" />
        <input type="button" name="button" value="Search" onclick="showUser()" class="button"/>
         <p>
             <div id="txtHint"></div>
         </p>
    </form>
</body>

search.css:

.button {
    background-image: url ('/image/btn.png') no-repeat;
    cursor:pointer;
}

what could be wrong?

even inline-ing the css didn't seem to work.


Solution

  • You need to type it without the word image.

    background: url('/image/btn.png') no-repeat;

    Tested both ways and this one works.

    Example:

    <html>
        <head>
            <style type="text/css">
                .button{
                    background: url(/image/btn.png) no-repeat;
                    cursor:pointer;
                    border: none;
                }
            </style>
        </head>
        <body>
            <input type="button" name="button" value="Search" onclick="showUser()" class="button"/>
            <input type="image" name="button" value="Search" onclick="showUser()" class="button"/>
            <input type="submit" name="button" value="Search" onclick="showUser()" class="button"/>
        </body>
    </html>