I am in the middle of creating an HtmlHelper method to generate code for various html elements with a width
and height
. I have a class like the following simplified example.
public class Media {
public string Url { get; set; }
public System.Drawing.Size Size { get; set; }
}
I will be generating some HTML like the following.
<video width="360" height="280">
<source src="{Media.Url}" type="video/mp4"></source>
</video>
OR
<div style="width:100%;height:50%;background: url({Media.Url});">
...
</div>
However, I would like to be able to store width
and height
as either pixels OR as percentages in my Media
class. I considered just storing the values as strings, but in my application, I need to be able to multiply and divide the values because I am going to scale the elements at various parts of my site.
Is there something built into the .Net Framework that makes managing sizes as pixels or percentages easy?