Web Analytics Made Easy -
StatCounter How to establish the width of a span - CodingForum

Announcement

Collapse
No announcement yet.

How to establish the width of a span

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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; Jul 11, 2002, 08:28 AM.
    Daniel

  • #2
    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>

    Comment


    • #3
      Works great thanks
      Daniel

      Comment

      Working...
      X