HTML: How to make a submit button with text + image in it?

后端 未结 10 774
抹茶落季
抹茶落季 2020-12-13 07:09

I would like to have a submit button which contains text and an image. Is this possible?

I can get the exact look I want with code that looks like:

相关标签:
10条回答
  • 2020-12-13 07:12

    Let's say your image is a 16x16 .png icon called icon.png Use the power of CSS!

    CSS:

    input#image-button{
        background: #ccc url('icon.png') no-repeat top left;
        padding-left: 16px;
        height: 16px;
    }
    

    HTML:

    <input type="submit" id="image-button" value="Text"></input>
    

    This will put the image to the left of the text.

    0 讨论(0)
  • 2020-12-13 07:12

    Please refer to this link. You can have any button you want just use javascript to submit the form

    http://www.w3schools.com/jsref/met_form_submit.asp

    0 讨论(0)
  • 2020-12-13 07:14

    In case dingbats/icon fonts are an option, you can use them instead of images.

    The following uses a combination of

    • an icon font (e.g. Font Awesome),
    • character encodings in HTML (e.g. &#xf090)
    • the Unicode code point of the icon you want to use (e.g. &#xf090 for the sign in logo),
    • CSS:

    In HTML:

    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
    
    <form name="signin" action="#" method="POST">
        <input type="text" name="text-input" placeholder="&#xf183; your username" class="stylish"/><br/>
        <input type="submit" value="&#xf090; sign in" class="stylish"/>
    </form>
    

    In CSS:

    .stylish {
        font-family: georgia, FontAwesome;
    }
    

    jsFiddle

    Notice the font-family specification: all characters/code points will use georgia, falling back to FontAwesome for any code points georgia doesn't provide characters for. georgia doesn't provide any characters in the private use range, exactly where FontAwesome has placed its icons.

    0 讨论(0)
  • 2020-12-13 07:14

    Here is an other example:

    <button type="submit" name="submit" style="border: none; background-color: white">
    

    0 讨论(0)
  • 2020-12-13 07:18

    You can do this:

    HTML code:

        <form action="submit.php" method="get" id="form">        
        <a href="javascript: submitForm()">        
        <img src="save.gif" alt="Save icon"/>        
        <br/>        
        save        
        </a>        
        </form>        
    

    note: you can use and action and method of your choice and Id and any text starting from href="javascript: and ending to ()" but make sure that when I type the same things such as id and some text you type in your replacement in the same places(java script and HTML code).

    java script code:

        var form=document.getElementById("form");        
        function submitForm()        
        {        
        form.submit();       
        }         
    
    0 讨论(0)
  • 2020-12-13 07:20

    I have found a very easy solution! If you have a form and you want to have a custom submit button you can use some code like this:

    <button type="submit">
        <img src="login.png" onmouseover="this.src='login2.png';" onmouseout="this.src='login.png';" />
    </button>
    

    Or just direct it to a link of a page.

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