CSS Font Width Calculation
Posted on 2010-01-04
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