How to put a jpg or png image into a button in HTML

后端 未结 8 2179
面向向阳花
面向向阳花 2020-12-09 16:57

I want a button with an image in it. I am using this:

 

But it do

相关标签:
8条回答
  • 2020-12-09 17:39

    you can also try something like this as well

    <input type="button" value="text" name="text" onClick="{action}; return false" class="fwm_button">
    

    and CSS class

    .fwm_button {
       color: white;
       font-weight: bold;
       background-color: #6699cc;
       border: 2px outset;
       border-top-color: #aaccff;
       border-left-color: #aaccff;
       border-right-color: #003366;
       border-bottom-color: #003366;
     }
    

    An example is given here

    0 讨论(0)
  • 2020-12-09 17:40

    It should be

    <input type="image" id="myimage" src="[...]" />
    

    So "image" instead of "submit". It will still be a button which submits on click.

    If your image is bigger than the button which is shown; let's say the image is 200x200 pixels; add this to your stylesheet:

    #myimage {
        height: 200px;
        width: 200px;
    }
    

    or directly in the button tag:

    <input type="image" id="myimage" style="height:200px;width:200px;" src="[...]" />
    

    Note however that resizing the image like this might not yield ideal results; if e.g. your image is much smaller than you want it to be shown, you will see the single pixels; if on the other hand it is much bigger, you are wasting precious bandwidth of your users. So resizing the picture itself to the actual size is preferrable over rescaling via stylesheets!

    0 讨论(0)
提交回复
热议问题