Let's say we have got a tag font-size:65%;
How do we can change it with pt
or px
?
Thank you!
It looks like this post here is a good resource.
The code from here seems to be close to what you need, specifically:
switch (unitSize.Unit.Type)
{
case UnitType.Pixel:
result = (int)Math.Round(unitSize.Unit.Value);
break;
case UnitType.Point:
result = (int)Math.Round(unitSize.Unit.Value*1.33);
break;
case UnitType.Em:
result = (int)Math.Round(unitSize.Unit.Value * 16);
break;
case UnitType.Percentage:
result = (int)Math.Round(unitSize.Unit.Value * 16 / 100);
break;
default:
// other types are not supported. just return the medium
result = 16;
break;
}
After a second glance it seems like something like this is more accurate but I have not really tested it throughout.
public int PercentToPoint(int percent)
{
return (int)Math.Round(Convert.ToDouble(percent * 12 / 100));
}
public int PercentToPixel(int percent)
{
return (int)Math.Round(Convert.ToDouble(percent * 16 / 100));
}
You cannot, any more than you can convert meters to seconds.
If you know the font size of the parent in element in some unit, then you can calculate the computed value corresponding to font-size: 65%
in that same unit by multiplying the numeric value of the parent font size by the number 0.65. But this would just mean calculating the value in a specific situation, not generally converting the relative value 65% to an absolute value.
I doubt the is a prebuild function in .net that would easily help you do it without writing your own converter but this jquery converter might help you:
To help you more, if you know the width, you can use the below formula to figure out px.
Say you have a container div 800px wide, if you have a col div in the container 384px wide that would be 48%:
384 / 800 = 48%