# Is there a function for calculating the dimension (not length) of a st

Page 1 of 1

## 4 Replies - 859 Views - Last Post: 02 July 2009 - 11:28 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=112867&amp;s=cb38f51bffa3b89a1d8ed023017ddb77&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 livium

Reputation: 0
• Posts: 543
• Joined: 21-December 08

# Is there a function for calculating the dimension (not length) of a st

Posted 02 July 2009 - 10:44 AM

Is there a function for calculating the dimension (not length) of a string? Because the dimension of 'a' is bigger than that of 'l'. I need such a function very baddly because i wanna calculate the number of spaces that i must put between two strings that are put in a fixed div, so that the first string is align to the left of the div and the other is align to the right of it.
So... is there such a function?
Is This A Good Question/Topic? 0

## Replies To: Is there a function for calculating the dimension (not length) of a st

### #2 Dantheman

• D.I.C Regular

Reputation: 34
• Posts: 445
• Joined: 27-May 09

## Re: Is there a function for calculating the dimension (not length) of a st

Posted 02 July 2009 - 11:12 AM

Functions deal with the string data. The dimension is not a string data. It's a font-dependent, screen-dependent, platform-dependent, monitor-dependent .... attribute.

Use a monospaced font, then every character will have the same dimension.

### #3 RudiVisser

• .. does not guess solutions

Reputation: 1010
• Posts: 3,566
• Joined: 05-June 09

## Re: Is there a function for calculating the dimension (not length) of a st

Posted 02 July 2009 - 11:18 AM

If you use CSS pt (points) instead of px (pixels) for positioning, it's supposed to make it easier to work with situations like this.

I don't really believe it, but hey.

You could also make your own function, store widths of characters in an array, loop through the string, and add up all the widths.

### #4 livium

Reputation: 0
• Posts: 543
• Joined: 21-December 08

## Re: Is there a function for calculating the dimension (not length) of a st

Posted 02 July 2009 - 11:22 AM

Thanks. I will use a monospace then.

MageUK, on 2 Jul, 2009 - 10:18 AM, said:

If you use CSS pt (points) instead of px (pixels) for positioning, it's supposed to make it easier to work with situations like this.

I don't really believe it, but hey.

You could also make your own function, store widths of characters in an array, loop through the string, and add up all the widths.

thanks, but that's to hard to do. I'll try using monospace.

### #5 CTphpnwb

• D.I.C Lover

Reputation: 3734
• Posts: 13,579
• Joined: 08-August 08

## Re: Is there a function for calculating the dimension (not length) of a st

Posted 02 July 2009 - 11:28 AM

What's wrong with using text-align?
http://htmlhelp.com/...text-align.html