0

Possible Duplicate:
Best Way to Sprite Images?

I have the following image that I want to use for users to log into site.

http://dl.dropbox.com/u/7468116/facebook_signin.png

However I am not able to make css work properly.

Community
  • 1
  • 1
Nick Vanderbilt
  • 36,724
  • 29
  • 83
  • 106

4 Answers4

2
.sprite {
background-image: url("pathto/facebook_signin.png");
background-position: 0 0;
}

.sprite:hover {
background-position: 0 16px /*or whatever the y position of the 2nd button is*/
}

.sprite:active {
background-position: 0 32px /*or whatever the y position of the 3rd button is*/
}
Graham Conzett
  • 8,344
  • 11
  • 55
  • 94
1

Something like this should work:

a.fb {
    display: block;
    background: ("/path/to/sprite.png") 0 0 no-repeat; /* start with normal state */
    width: 150px;
    height: 18px;
    text-indent: -9999px; /* for image replacement */
}
    a.fb:hover,
    a.fb:focus {
        /* hover and focus state */
        background-position: 0 -20px;
    }
    a.fb:active {
        /* click state */
        background-position: 0 -40px;
    }
Chris
  • 3,729
  • 22
  • 30
1

If you are on mac, you can use some tools for writing your CSS file automatically. These tools are ordering your sprites in an effective way and also writes CSS files for you. You don't need to fight with ordering and calculating pixel coordinates, etc. I suggest Sprite Master.

bateristt
  • 176
  • 15
0

What exactly's not working in your CSS? Spriting is involves changing the background position of the image on hover (or other states).

So it's really just

#element {
  background-position-y: 10px;
}
#element:hover {
  background-position-y: 0px;
}

Would be helpful to see your CSS.

fiiv
  • 1,267
  • 1
  • 8
  • 16
  • 2
    just use position without the -y and give the both values. This syntax is not very well supported. (sadly) – meo Jan 27 '11 at 20:54