I have a project where I am building slides described inside of an XML file but it requires to allow image positioning of the slides based on offset values.
Now I have Y offsets down pat, only problem now is that I require the ability to offset something in the X by an amount but still keep the %'age value behavior.
So basically is there anyway to have background-position's x start at 50% and then offset it by a pixel amount and keep the relative behavior of the %'age( 50% + offsetInPixels)?
The background-position CSS property sets the initial position for each background image. The position is relative to the position layer set by background-origin .
The default values are 0 0 . This places your background image at the top-left of the container. Length values are pretty simple: the first value is the horizontal position, second value is the vertical position. So 100px 5px will move the image 100px to the right and five pixels down.
The background-image property is used to set one or more background images for an element. By default, it places the image on the top left corner. To specify two or more images, we need to specify the separate URLs with a comma for both images.
The background-attachment property in CSS specifies how to move the background relative to the viewport. There are three values: scroll , fixed , and local .
You can do this, but it isn't widely supported.
background-position: -moz-calc(50% - 20px) 0;
background-position: calc(50% - 20px) 0;
Currently (May 2011) this only works in Firefox 4 and IE9.
See http://caniuse.com/#calc for compatibility.
You can't do that with plain CSS (at this point in time, see Rich Bradshaw's answer).
You could accomplish that in javascript with something like:
var totalWidth = 960;
var xOffset = 10;
el.style.backgroundPosition = ((totalWidth/2) + xOffset) +"px 50px";
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