Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit Button Image

Tags:

html

css

submit

I want to use a Submit Button Image instead of the standard Button. I searched on Google and SO and got a few different ways.

Which is the right way of using an Image as a Submit Button ?

Also i would want to add three states for the button - normal, hover, onclick

What i tried

HTML

<input type="submit" value="Subscribe">

CSS

input[type=submit] {
    background:url(../images/btn-subscribe.gif) none;
    text-indent:-9999px;
    width:109px;
    height:41px;
}

What shows up

enter image description here

What it should Display

enter image description here

like image 987
Harsha M V Avatar asked Aug 02 '12 06:08

Harsha M V


People also ask

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 make an image a button?

Placing the <img> tag inside the <button> tag creates a clickable HTML button with an image embedded in it.

What is button submit?

Definition and Usage. The <input type="submit"> defines a submit button which submits all form values to a form-handler. The form-handler is typically a server page with a script for processing the input data. The form-handler is specified in the form's action attribute.


2 Answers

Edited:

I think you are trying to do as done in this DEMO

There are three states of a button: normal, hover and active

You need to use CSS Image Sprites for the button states.

See The Mystery of CSS Sprites

/*CSS*/

.imgClass { 
background-image: url(http://inspectelement.com/wp-content/themes/inspectelementv2/style/images/button.png);
background-position:  0px 0px;
background-repeat: no-repeat;
width: 186px;
height: 53px;
border: 0px;
background-color: none;
cursor: pointer;
outline: 0;
}
.imgClass:hover{ 
  background-position:  0px -52px;
}

.imgClass:active{
  background-position:  0px -104px;
}
<!-- HTML -->
<input type="submit" value="" class="imgClass" />
like image 174
Ahsan Khurshid Avatar answered Sep 30 '22 19:09

Ahsan Khurshid


<input type="image" src="path to image" name="submit" />

UPDATE:

For button states, you can use type="submit" and then add a class to it

<input type="submit" name="submit" class="states" />

Then in css, use background images for:

.states{
background-image:url(path to url);
height:...;
width:...;
}

.states:hover{
background-position:...;
}

.states:active{
background-position:...;
}
like image 34
asprin Avatar answered Sep 30 '22 18:09

asprin