Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an image button in CSS - image:active

Tags:

css

I'm trying to replace the submit button with an image by defining it in a class="myButton" and change the styles in CSS. the myButton:active doesn't seem to work when being clicked.

Here is my CSS:

.myButton{
    background:url(./images/but.png) no-repeat;
    cursor:pointer;
    border:none;
    width:100px;
    height:100px;
}

myButton:active {
     background:url(./images/but2.png) no-repeat;
}

HTML code:

<input class="myButton" type="submit" value="">
like image 271
user1666411 Avatar asked Sep 22 '12 12:09

user1666411


People also ask

How do you make an image clickable in CSS?

Complete HTML/CSS Course 2022 To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image.

How do I make an image act as a button?

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.

Can you put an image in a button?

Button with an ImageYou 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.


1 Answers

Check this link . You were missing . before myButton. It was a small error. :)

.myButton{
    background:url(./images/but.png) no-repeat;
    cursor:pointer;
    border:none;
    width:100px;
    height:100px;
}

.myButton:active  /* use Dot here */
{   
    background:url(./images/but2.png) no-repeat;
}
like image 198
Mr_Green Avatar answered Oct 05 '22 22:10

Mr_Green