Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an image to submit button using CSS

Tags:

html

css

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.

like image 367
JCW Avatar asked Jan 03 '14 13:01

JCW


People also ask

Can you put an image in a button CSS?

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.

Can you use an image as a submit button?

Definition and UsageThe <input type="image"> defines an image as a submit button. The path to the image is specified in the src attribute.

How do I put an image inside a button?

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.

How do I add an image to a button tag?

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.


3 Answers

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;
}
like image 149
jfelsinger Avatar answered Oct 06 '22 21:10

jfelsinger


Add value with empty string to the input:

<input type="submit" id="search" name="submit" alt="search" value="">
like image 41
Bud Damyanov Avatar answered Oct 06 '22 23:10

Bud Damyanov


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

like image 1
AmanS Avatar answered Oct 06 '22 22:10

AmanS