Ramya
Ramya

Reputation: 1354

Why image sprites take negative coordinates for background position

I know the popular feature in css in Image sprites. But I don't understand why we have to specify background-position coordinates negative. I know for any image sprite the top left corner serves as origin. I don't understand why so? Why not other corners and why not center of the image sprite. If any body knows answer for this. Please help

Upvotes: 1

Views: 1652

Answers (2)

Dennis Traub
Dennis Traub

Reputation: 51694

We need a coordinate system to describe an image. The coordinate system that is used in computer imaging is based on bitmaps and bitmaps by definition are based on a grid (rows and columns) with its orign (x = 0, y = 0) in the upper left corner (as opposed to the cartesian coordinate system, which has the origin of its positive space in the lower left.)

Upvotes: 4

Andy
Andy

Reputation: 14575

You use negative co-ordinates because you want the image to "start later".

For example, I have a 100px by 100px image, and a square that starts at co-ordinates 40,40

I want to move the image 40 pixels to the left and top, so the square comes into my view, i do this by doing background:url('sprite.png') -40px -40px;

Upvotes: 3

Related Questions