javascript - convert padding from pixels to percentage -


i've been looking around in existing threads find solution, nothing applies specific situation.

i have hyperlink absolute positioning inside relative positioned div. padding , margins defined pixels, want redefine them in percentages.

for example, this:

<a id="original" href="www.google.com" style="display: inline-block; position:absolute; left: 150px; top: 300px; padding: 100px 100px;" /> 

becomes this:

<a id="inserted" href="www.google.com" style="display: inline-block; position: absolute; left: 18.38235294117647%; top: 28.40909090909091%; padding: 9.469696969696969% 12.254901960784313%;"></a> 

this jsfiddle example shows want achieve. you'll notice size of converted paddings aren't large (in height) original link.

hopefully description clear enough. otherwise, let me know ;)

when specifying padding in percentage, in reference width , not height. have specify value as

a.style.padding = awidth / 816 * 100 + "%" +                   awidth / 816 * 100 + "% "; 

click here modified sample code

workaround can found here


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -