Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 button background image states

Tags:

html

css

I have a button and im trying to apply this image to its background, the green is the off state and yellow is the on click state. Can I use this image where both states are in same file or do I need to separate them? What is the standard for this situation and how does the css work?

enter image description here

<button>click me</button>
button {
    background-image:url('button.png');
}
like image 370
nick Avatar asked Dec 01 '22 19:12

nick


1 Answers

Yes you can definitely use them. They're called CSS Sprites.

Here is a fiddle

button{
    width:196px;
    height:64px;
    background-image:url("http://i.stack.imgur.com/BSVeQ.gif");
    background-repeat:no-repeat;
}
button:active{
    background-position:0px -64px;
}
like image 142
Lokesh Suthar Avatar answered Dec 04 '22 09:12

Lokesh Suthar