I’m looking for the simplest and cross browser way to convert html element css margin value to absolute pixels. Say for instance the margin is “auto”.
I can’t use any js framework.
I’m looking for the simplest and cross browser way to convert html element css
Share
You want to use the
window.getComputedStylemethod:Here’s a working demo: http://jsfiddle.net/VxccZ/
Update
For IE 8 and older (that do not support this method), use the
currentStyleproperty of your element:To summarize:
I’m not 100% sure that
currentStylefeatures a numeric value formargin: auto. You will have to try that yourself. I cannot do that myself on the Mac.