HTML / CSS How to add image icon to input type=“button”?

前端 未结 12 1671
误落风尘
误落风尘 2020-11-28 20:21

I\'m using the below CSS, but it puts an image in the center of the button. Any way to left or right align an icon using , so that

相关标签:
12条回答
  • 2020-11-28 20:55

    Simply add icon in button element here is the example

       <button class="social-signup facebook"> 
         <i class="fa fa-facebook-official"></i>  
          Sign up with Facebook</button>
    
    0 讨论(0)
  • 2020-11-28 20:55

    sshow's answer did it for me, too:

    navigation.css:

    [...]
    
    .buttonConfiguration {
        width: 40px;
        background-color: red; /* transparent; */
        border: none;
        color: white;
        padding: 5px 10px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-family: corbel;
        font-size: 12px;
        font-weight: normal;
        margin: 1px 1px;
        cursor: pointer;
    
        background-image: url('../images/icons5/gear_16.png');
        background-position: center; /* 0px 0px; */
        background-repeat: no-repeat;
        vertical-align: middle;
    }
    
    [...]
    

    frameMenu.php:

    [... PHP, Javascript and HTML code ...]
    
    <!-- <li><a target="frameBody" href="admin/conf/confFunctions.php"><input type="button" class="buttonSuperAdmin" value="<?= $oLanguage->getExpression('confSettings', 'title', 'C e n t e r s') ?>"></a> -->
    <li><a target="frameBody" href="admin/conf/confFunctions.php"><input type="button" class="buttonConfiguration" value=""></a>
    <ul>
    <li><a target="frameBody" href="admin/conf/getglobals.php "><input type="button" class="buttonSuperAdminSub" value="<?= $oLanguage->getExpression('centerSettings', 'confAdmin1', 'GetGlobals') ?>"></a></li>
    <li><a target="frameBody" href="admin/conf/getcwd.php "><input type="button" class="buttonSuperAdminSub" value="<?= $oLanguage->getExpression('confSettings', 'centerAdmin2', 'GetCWD') ?>"></a></li>
    </ul>
    </li>
    
    [...]
    

    I have tested this successfully under the lastest versions of Firefox and Chrome (as of February 9th, 2019).

    0 讨论(0)
  • 2020-11-28 20:58

    If you absolutely must use input, try this:

    background-image: url(...);
    background-repeat: no-repeat;
    background-position: <left|right>;
    padding-<left|right>: <width of image>px;
    

    It's usually a little easier to use a button with an img inside:

    <button type="submit"><img> Text</button>
    

    However the browser implementations of button for submitting are inconsistent, as well as the fact that all button values are sent when button is used - which kills the "what button clicked" detection in a multi-submit form.

    0 讨论(0)
  • 2020-11-28 21:03
    <button type="submit" style="background-color:transparent; border-color:transparent;"> 
      <img src="images/button/masuk.png" height="35"/>
    </button>
    <button type="reset" style="background-color:transparent; border-color:transparent;"> 
      <img src="images/button/reset.png" height="35"/>
    </button>
    

    I hope this helps you.

    0 讨论(0)
  • 2020-11-28 21:04

    If you're using spritesheets this becomes impossible and the element must be wrapped.

    .btn{
        display: inline-block;
        background: blue;
        position: relative;
        border-radius: 5px;
    }
    .input, .btn:after{
        color: #fff;
    }
    .btn:after{
        position: absolute;
        content: '@';
        right: 0;
        width: 1.3em;
        height: 1em;
    }
    .input{
        background: transparent;
        color: #fff;
        border: 0;
        padding-right: 20px;
        cursor: pointer;
        position: relative;
        padding: 5px 20px 5px 5px;
        z-index: 1;
    }
    

    Check out this fiddle: http://jsfiddle.net/AJNnZ/

    0 讨论(0)
  • 2020-11-28 21:05

    This works well for me, and I'm handling hover and click CSS as well (by changing background color):

    HTML (here showing 2 images, image1 on top of image2):

    <button class="iconButton" style="background-image: url('image1.png'), url('image2.png')"
      onclick="alert('clicked');"></button>
    

    CSS (my images are 32px X 32px, so I gave them 4px for padding and a 5px border rounding):

    .iconButton {
        width: 36px;
        height: 36px;
        background-color: #000000;
        background-position: center;
        background-repeat: no-repeat;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        outline: none;
    }
    
    .iconButton:hover {
        background-color: #303030;
    }
    
    .iconButton:active {
        background-color: #606060;
    }
    
    button::-moz-focus-inner {
        border: 0;
    }
    
    0 讨论(0)
提交回复
热议问题