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.
If anyone could suggest what the problem might be, it would be greatly appreciated.
The default button in HTML can be changed to an image using CSS. The required button is selected using the respective CSS selector. The background property can then be set to include a background image and change the image type as required. The border of the button can also be removed to show only the image itself.
Definition and UsageThe <input type="image"> defines an image as a submit button. The path to the image is specified in the src attribute.
You can include an <img> element inside your <button> element to display the image on the button. You can still add text to the button, resulting in a combination of image and text.
The image buttons in the HTML document can be created by using the type attribute of an <input> element. Image buttons also perform the same function as submit buttons, but the only difference between them is that you can keep the image of your choice as a button.
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;
}
Add value
with empty string to the input:
<input type="submit" id="search" name="submit" alt="search" value="">
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With