www.webdeveloper.com
Results 1 to 4 of 4

Thread: getting pixel length of text

  1. #1
    Join Date
    Apr 2008
    Posts
    28

    getting pixel length of text

    Are there any methods that I can use to get the pixel length of a text element? The text element would change pixel length depending on its font.

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    To the best of my knowledge no. You can get the length the container it's in if that is any use to you, I'm not sure the information you've given.
    Great wit and madness are near allied, and fine a line their bounds divide.

  3. #3
    Join Date
    Sep 2006
    Location
    Copenhagen, Denmark
    Posts
    1,253
    A span element with no padding should have the same length as the text which it contains.
    #define question (2B || !2B)
    HTMLElement and W3C Event Handling in IE
    My JavaScript Library

    Don't PM me about answers to questions. If I don't reply in a thread it's because:
    • You didn't read the message posting guidelines
    • Your code is too unstructured and/or formatted poorly - correcting it is too time consuming
    • I simply don't know the answer

  4. #4
    Join Date
    Apr 2008
    Posts
    28
    I used Span.

    Just had to set:
    .style.whiteSpace = "nowrap";

    and then use the .offsetWidth property to get the width.

    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles