By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,576 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

How to calculate the height of a text?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.