4 Replies - 876 Views - Last Post: 02 July 2009 - 11:28 AM Rate Topic: -----

#1 livium   User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • 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   User is offline

  • D.I.C Regular

Reputation: 34
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 RudiVisser   User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1010
  • View blog
  • 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.
Was This Post Helpful? 1
  • +
  • -

#4 livium   User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • 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.

View PostMageUK, 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.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3786
  • View blog
  • Posts: 13,715
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1