CSS Font Width Calculation

Hi All,

The issue that I've come across is that I have a label that displays the month of the year and I need to calculate the width of the month so that all months are approximately 130 pixels in length. What I was hoping to do is to change the letter-spacing style on the fly but I'm having a real hard time getting the width of the text. So for example if I am using Arial and a font size of 16 I need to find the calculation to make sure that the month of JULY is approximately the same width as DECEMBER.  

The System.Drawing.Graphics class for windows development has a method called MessageString but I cannot seem to find a similar method for ASP .NET. Also I tried to cheat and just get the Label.Width.Value and do a calculation with that but it returns a value of 0 in the Page_Load method. Also if there is a slick way to do this just using CSS I'd love to know it.

Any help would be greatly appreciated

Thanks
LVL 2
aiuWebServicesAsked:
Who is Participating?
 
kumar754Commented:
this will give you width of a font in pixels:

System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(100,100);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
float fontWidthInPixel = g.MeasureString("July", new System.Drawing.Font("Arial", 16, System.Drawing.GraphicsUnit.Pixel)).Width;

rest you can figure out what to do with the font width and to manage your code accordingly.
0
 
russellCCommented:
can I ask why they need to be the same width?  It may look weird if you do not change the hight also, this could possibly stretch your letters to look funny on months like july.
0
 
Bob LearnedCommented:
I believe that what you are talking about concerns using kerning techniques.

Understanding Typography Controls with CSS
http://www.creativepro.com/article/understanding-typography-controls-with-css

"Kerning and Leading
Probably the most interesting of the new properties are the kerning and leading settings. If you don't already know, kerning is the spacing between letters and leading is the spacing between lines. Leading controls are an especially nice feature of CSS, as there's no such thing as one-size-fits-all leading. Some fonts need more, while others need less to make them more readable."
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.