How to calculate the height of a text?

Z

Zsolt Koppany

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
 
E

Evertjan.

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>
 
Z

Zsolt Koppany

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
 
E

Evertjan.

Zsolt Koppany wrote on 18 nov 2003 in comp.lang.javascript:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top