Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

background-position: -209px -2px, I don't understand negative background position

Tags:

css

If I have a 1000x3000 px image and I use a negative background position, how does this exactly work?

I thought it worked by moving to the left 209 pixels then moving up 2 pixels and then showing the part that actually is left, but it seems to do the opposite of that.

like image 655
Chris Muench Avatar asked Aug 24 '11 19:08

Chris Muench


People also ask

How is background position calculated?

The four-value syntax for background-position You combine length values with any of top/right/bottom/left keywords (not center). So for our example: background-position: right 20px bottom 10px; Using this, you can offset a background-image from any of the four corners of an element.

How do you change the background position percentage?

The percentage offset of the given background image's position is relative to the container. A value of 0% means that the left (or top) edge of the background image is aligned with the corresponding left (or top) edge of the container, or the 0% mark of the image will be on the 0% mark of the container.

What is background position y?

The background-position-y CSS property sets the initial vertical position for each background image. The position is relative to the position layer set by background-origin .

What is background position in computer?

Background PositionThe background-position property specifies the initial position where the background image will be placed inside of the element it is the background for. You can set both the horizontal and vertical position. Options for setting the horizontal position are left, right and center.


2 Answers

Background position property actually moves the background image itself relative to the element. For the instance if you use {background-position: 0 0} that means you are positioning (0,0) which is top left of your image to the top left of your html element.

The -ve left offset means you are moving the image towards left and the -ve top offset means moving the image upwards..

In above code first 0 refers to left offset and second 0 refers to the top offset..

{background-position: -209px -2px}

means you are moving your image 209px towards left and 2px upwards.

Hope this will help you.

like image 135
Sushanta Patel Avatar answered Nov 08 '22 16:11

Sushanta Patel


You should interpret the negative signs as:

background-position: -x, -y; is the same as saying... background-position: x pixels left, y pixels up;

like image 36
Mike Vysocka Avatar answered Nov 08 '22 15:11

Mike Vysocka