469,923 Members | 1,745 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

How to calculate the height of a text?

Hi,

I use dynamic menus and would like to know how I can figure out the height
of a text (for exalple "Product"). I need it to calculate text positions.

Zsolt
Jul 20 '05 #1
3 11750
Zsolt Koppany wrote on 18 nov 2003 in comp.lang.javascript:
I use dynamic menus and would like to know how I can figure out the
height of a text (for exalple "Product"). I need it to calculate text
positions.


IE:

<div id=Product
style="width:1px;height:1px;padding:0;font-size:21pt;"
onclick="alert(this.clientHeight+' px height')">
Product</div>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
Evertjan,

thank you for the answer.

Do you have a function that for example gets a string as an input parameter
and calculates the height of the string with a specific font?

Zsolt
"Evertjan." <ex**************@interxnl.net> schrieb im Newsbeitrag
news:Xn********************@194.109.133.29...
Zsolt Koppany wrote on 18 nov 2003 in comp.lang.javascript:
I use dynamic menus and would like to know how I can figure out the
height of a text (for exalple "Product"). I need it to calculate text
positions.


IE:

<div id=Product
style="width:1px;height:1px;padding:0;font-size:21pt;"
onclick="alert(this.clientHeight+' px height')">
Product</div>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jul 20 '05 #3
Zsolt Koppany wrote on 18 nov 2003 in comp.lang.javascript:
"Evertjan." <ex**************@interxnl.net> schrieb im Newsbeitrag
news:Xn********************@194.109.133.29...
Zsolt Koppany wrote on 18 nov 2003 in comp.lang.javascript:
> I use dynamic menus and would like to know how I can figure out the
> height of a text (for exalple "Product"). I need it to calculate
> text positions.

<div id=Product
style="width:1px;height:1px;padding:0;font-size:21pt;"
onclick="alert(this.clientHeight+' px height')">
Product</div>

Do you have a function that for example gets a string as an input
parameter and calculates the height of the string with a specific
font?


[please do not underquote on usenet]

<div id=Test
style="position:absolute;visibility:hidden;height: 1px;">x
</div>

<SCRIPT>
function TextHeight(text,points,family){
test=document.getElementById("Test")
test.style.fontFamily=family
test.style.fontSize=points
test.innerHTML=text
return test.clientHeight+' px height'
}

alert("Arial: "+TextHeight("Product","41pt","Arial"))
alert("Verdana: "+TextHeight("Product","41pt","Verdana"))
</SCRIPT>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Building Blocks | last post: by
1 post views Thread by comp.lang.php | last post: by
12 posts views Thread by paii, Ron | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.