9

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

HTML

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

CSS

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

This returns this submit button, but I don't want the word 'submit' or the gray square box to appear.

http://cs12jcw.icsnewmedia.net/screenshot.png

If anyone could suggest what the problem might be, it would be greatly appreciated.

Moduo
  • 623
  • 6
  • 17
JCW
  • 139
  • 1
  • 1
  • 7

9 Answers9

16

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;
}
jfelsinger
  • 444
  • 3
  • 12
1

Add value with empty string to the input:

<input type="submit" id="search" name="submit" alt="search" value="">
Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
1

instead of input type="submit" you can use input type="image"

use this one line code

<input type="image" src="submit.gif" alt="Submit" width="48" height="48">

see DEMO

AmanS
  • 1,490
  • 2
  • 13
  • 22
0

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

putvande
  • 15,068
  • 3
  • 34
  • 50
0

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

<input type="submit" id="search" name="submit" alt="search" value="" >
SpiderCode
  • 10,062
  • 2
  • 22
  • 42
0

try this

input#search {
background:url(../search-icon.png) no-repeat;
width:40px;
height:40px;
text-indent:50px;
overflow:hidden;
}
0
<!DOCTYPE html>
<html>
       <head>
       <style>
            input.search{
                background-image:url(url.jpg);
                text-indent:-9999px;
                width: 100px;
                height: 30px;
                border:2px solid rgb(0,102,153);
           }
       </style>
       </head>

       <body>
       <input type="submit" class="search" alt="search">
</body>
</html> 

enter image description here

Asraful Haque
  • 1,109
  • 7
  • 17
0

I find this to be the most complete solution:

#submitbutton {
    background-image: url(http://paulabrown.net/search-button-png-210.png);
    background-repeat: no-repeat;
    height: 24px; // height of image
    width: 24px; // width of image
    padding: 0;
    border: none; // get rid of grey border
    color: transparent; // hide the text (without indenting it to hell)
    background-color: transparent;
    outline: none;
    display: block; // Ensure block element to apply this to inline-elements
}
d4nyll
  • 11,811
  • 6
  • 54
  • 68
0
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;
}
Sudhi
  • 1