Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to establish the width of a span

    I need to calculate the width of a span taking into account the font and size of it's contents. I want to use that width to position the span with a style:"position;absolute; left:xxx;" that will change depending on the with of the span.

    Can anyone help me on this?

    Thanks
    Last edited by DanLap; 07-11-2002 at 02:28 PM.
    Daniel

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Something like this ought to do it:

    Code:
    <span id="theSpan"><img src="image1.gif"></span>
    <script>
    if (document.layers){
      w=document.layers["theSpan"].clip.width;
    } else if (document.all && !document.getElementById){
      w=document.all["theSpan"].offsetWidth;
    } else if(document.getElementById){
      w=document.getElementById("theSpan").offsetWidth;
    }
    
    alert(w);
    
    </script>

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Works great thanks
    Daniel


  •  

    Posting Permissions

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