In one of my sites I had a dynamic drop-down list composed of a <div> full of <a> tags made to look like buttons and aligned vertically with <br>. The problem I had was that I didn't know in advance what text was going into these buttons, so had to generate the width dynamically. I couldn't just let the browser size the buttons, as they'd all be different lengths and would look ridiculous.
For want of any better solution, I ended up generating the buttons twice (clearing the div's innerHTML between the first and second passes so that I only ever saw the second-pass buttons). In the first-pass loop, I asked the <div> how wide it was - using the offsetWidth property. Then I used this value to size all the individual buttons during the second pass - ensuring that they were all as wide as the widest. You could probably use something similar to find the width of your text string. Note, however, that this would need to be done on the browser, not in the server. Dave S ----- Original Message ----- From: Niels Bieze To: [EMAIL PROTECTED] Sent: Wednesday, September 29, 2004 7:50 PM Subject: [ASP] Calculating the length of a string in pixels Hi all Is there someone that knows of a function/component that will calculate the length of a string in pixels? Say I have a string = "Brown Fox" the font is Arial, and the font-size = 10 Is it possible to calculate how long that string would be in pixels?? Any and all help is greatly appreciated Greetings --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/04 [Non-text portions of this message have been removed] ------------------------ Yahoo! Groups Sponsor --------------------~--> Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar. Now with Pop-Up Blocker. Get it for free! http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/17folB/TM --------------------------------------------------------------------~-> --------------------------------------------------------------------- Home : http://groups.yahoo.com/group/active-server-pages --------------------------------------------------------------------- Post : [EMAIL PROTECTED] Subscribe : [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] --------------------------------------------------------------------- Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/active-server-pages/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
