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.
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.
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.
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 .
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.
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.
You should interpret the negative signs as:
background-position: -x, -y; is the same as saying... background-position: x pixels left, y pixels up;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With