How can I make my <input type=“submit” /> an image?

前端 未结 6 1675
不知归路
不知归路 2021-02-02 11:07

I have a beautiful little CSS image that needs to be a button. I\'ve tried about 20 different methods, none of which work. I just either get a blank nothing or a border with no

6条回答
  •  时光取名叫无心
    2021-02-02 11:39

    You can override the style given by the browser to the button.

    For example adding this to your css does the trick for me (on Chrome):

    .controls input {
       background: url(' http://lrroberts0122.github.com/DWS/lab6/level-2/images/button.png') -411px -540px no-repeat;
       width: 199px;
       height: 109px;
       border: none;
    }
    

    But really if you are not going to use the browser's css for the button, you should probably not use at all, and just insert the image (via an tag or a

    with the image as background) and attach a click listener to it.

    For example:

    The html:

    The javascript (assuming you use jQuery):

    $('.controls img').click(function(){... stuff to do...});
    

提交回复
热议问题