I'm programming a little WP theme and need a little help with the new CSS3 background-size property.
I have a DIV which contains an image as background. The image itself is set bigger than the div to present a little cut-out of the original image:
.imageContainer {
background-size:154% 102%;
background-position-x:-28%;
background-position-y:0.28%;
}
So far everything is fine. But invoking the background-position property gets tricky if the size is ≥ 100%. I put together a little JS/CSS Playground for testing:
- If the image is ≤ 99% wide, less background-position-x means the image goes left.
- If the image is == 100% wide, background-position-x does nothing
- If the image is ≥ 101% wide, less background-position-x means the image goes right.
For the following case I calculated:
- Big container: 350x350px
- Image: 540x359px
- Means: (100/350) * 540 ≙ 154% width
- (100/350) * 359 ≙ 102% height.
- Also: position-x: -28% and position-y: -0.28%
So I rendered a page (incl. automatic calculations) and the size is about the right size. But as I said, less background-position-x (-28%) means the image goes right, the image has the wrong position.
It would have to be moved left, because I calculated -28% "left margin". So I did a bit trial and error and it turned out that the right position would be at something around 50%.
Is this still an CSS3 issue, or is it my complete misunderstanding of the functionality of this property?
EDIT: here is an JSFiddle too
Here is a picture to illustrate my target…