Results 1 to 6 of 6

Thread: Help. Get String width and height.

  1. #1
    Join Date
    Jun 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help. Get String width and height.

    Hi

    I m trying to make align and valign but for that i need
    the string width and height.
    I have look for it in books, forums, scripts and nothing,
    can some one help me ???

    Thanks for all the help you can give.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You will need to be more specific. Strings do not have width or height. If you want to get the width or height of an element, you can but, it depends upon wether these are already defined or not and if defined, how they are defined, as to what method you use. In all cases the element must have been parsed by the browser before you query its dimensions. Here are some examples:

    var element=document.getElementById('myID')

    //For elements with attribute width & height defined:

    alert(element.width);
    alert(element.height);

    //For elements with style width & height defined:

    alert(element.style.width);
    alert(element.style.height);

    //For elements with no defined width or height

    alert(element.offsetWidth);
    alert(element.offsetHeight);
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi

    Thanks for the help.

    <td> as the "align" and "valign" how do i do that in a <span>
    or <div> ???

    Span.height = 100
    String(Text).height = 20

    to align i do

    (Span.height - String(Text).height) / 2 = 40

    this is like the valign, but for this i need the String height.

  4. #4
    Join Date
    Oct 2007
    Location
    Germany, Berlin
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I had the same question!
    "element.offsetheight" doesn't work if height is set on "auto".
    Need help, please!!!!

    greetings
    Max

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by ReMaX View Post
    I had the same question!
    "element.offsetheight" doesn't work if height is set on "auto".
    Need help, please!!!!

    greetings
    Max
    element.offsetheight won't work for anything. It's (praise to the all mighty camelBackNotation ):

    Code:
    element.offsetHeight
    That should get you a number that represents the current layout height of the element in pixels, regardless of how it is styled.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Oct 2007
    Location
    Germany, Berlin
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Danke, man! Your my god!
    I didn' know that upper and lower case is important in JS! I started learning it the day I logged in here the first time.

Bookmarks

Posting Permissions

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