Adding an image to submit button using CSS

前端 未结 9 2123
面向向阳花
面向向阳花 2020-12-10 05:34

I\'m attempting to use CSS in order to make a sumbit button containing an image. Here\'s the code:

HTML



        
相关标签:
9条回答
  • 2020-12-10 05:59

    Add value with empty string to the input:

    <input type="submit" id="search" name="submit" alt="search" value="">
    
    0 讨论(0)
  • 2020-12-10 06:16
    html: <input type ="submit" value ="" class="search-button"/>
    CSS:
    .search-button
    {
        background-image: url("/images/search.png");
        background-repeat: no-repeat;
        min-width: 52px;
        min-height: 20px;
        width:52px;
        height: 20px;
        border:0;
    }
    
    0 讨论(0)
  • 2020-12-10 06:18

    The gray box is caused by a default border being added to the submit buttons. Whereas the submit text is the default value for the button.

    HTML:

    <input type="submit" id="search" name="submit" alt="search" value="">
    

    CSS:

    input#search    {
    background:url(../search-icon.png);
    background-repeat: no-repeat;
    width:40px;
    height:40px;
    border: 0;
    }
    
    0 讨论(0)
  • 2020-12-10 06:20

    Set blank Value of the input type submit as shown below :

    <input type="submit" id="search" name="submit" alt="search" value="" >
    
    0 讨论(0)
  • 2020-12-10 06:20

    try this

    input#search {
    background:url(../search-icon.png) no-repeat;
    width:40px;
    height:40px;
    text-indent:50px;
    overflow:hidden;
    }
    
    0 讨论(0)
  • 2020-12-10 06:24

    You can use CSS text-indent to move the text away:

    input#search {
        background:url(../search-icon.png);
        background-repeat: no-repeat;
        width:40px;
        height:40px;
        text-indent:-999px
    }
    

    https://developer.mozilla.org/en-US/docs/Web/CSS/text-indent

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