I want to work with CSS styles, so I get the needed info about this HTML
<img src="imagelink" id="IMG" style="margin: 5px 4em 3% 2%;">
by this code
if(window.getComputedStyle){
style = window.getComputedStyle(dom, null);
for(var i = 0, l = style.length; i < l; i++){
var prop = style[i];
var val = style.getPropertyValue(prop);
returns[prop] = val;
}
return returns;
}
Until now, I only work with "px", so all works fine. Now I try to work with the other units and just I get trouble.
Instead of 5px, 4em, 3%, 2%
, I receive from the computedStyle recalculate absolute values for "px".
"margin-inline-start": "21.3667px"
"margin-left": "21.3667px"
"margin-right": "48px"
"margin-top": "5px"
Why is it so and how I can prevent that? I want to work with the kind of unit which is defined in the inline CSS.
Recalculate this won't work, because I cannot see any info in the computedStyle that the original kind was not "px".
Thanks a lot for helping to understand and solving that.
UPDATE
I look around to find a way to get all matching rules for a element (css class, inline-style, @import and @media). But all what i find & read are half-workes or to old and wont work now)...i'm frustrated at this point