how to get the height of a text line

B

Bruce

Hi -

I've been looking all over for this and found everything but the
variation I need. I have a one-row HTML table with a page title, as
text, with a specified font and size (not style).

example:

<table... border=0>
<tr>
<td id="abc"> <font face="Arial" size="+2">This is my site</font>
</td>
etc. to close the table.

I know that if I put a "height=" in the "td" tag (or in a span tag), I
can retrieve its value with Javascript after the page is rendered.

But how can I get the ACTUAL number of pixels for the height that was
rendered by the browser for that text line, considering the font style
and size? I can't seem to find this anywhere. Is it possible? After
all, if the user changes his/her viewing text size, the font size will
increase/decrease and the # of pixels will change -- I don't oppose
this. But how can I get the actual size they are seeing?

Thanks.
 
A

Aaron Gray

I've been looking all over for this and found everything but the
variation I need. I have a one-row HTML table with a page title, as
text, with a specified font and size (not style).

example:

<table... border=0>
<tr>
<td id="abc"> <font face="Arial" size="+2">This is my site</font>
</td>
etc. to close the table.

I know that if I put a "height=" in the "td" tag (or in a span tag), I
can retrieve its value with Javascript after the page is rendered.

But how can I get the ACTUAL number of pixels for the height that was
rendered by the browser for that text line, considering the font style
and size? I can't seem to find this anywhere. Is it possible? After
all, if the user changes his/her viewing text size, the font size will
increase/decrease and the # of pixels will change -- I don't oppose
this. But how can I get the actual size they are seeing?

I believe the CSS text variable line-height is what you are wanting, so
presumable object.style.LineHeight will do the job ?##

Have not tried it though.

Aaron
 
B

Bruce xxxxxxxx

Thanks guys...

Yes, "line-height" accomplished what I need. Not exactly as I had in
mind but since it limits the expansion of the row, it's good.

Just curious now, since it no longe matters, but what would be the
better way of solving my original problem of the user changing the size
of font he sees?? What about getting the font's attributes, as you can
do in C++/MFC or in Java, then getting the height from that. I forgot
what the routine in C++/MFC is, but it's something like
s.GetStringWidth(), which gives the width in pixels of your string s.
------- or can I just use a mapping of font size to pixels? - I don't
know the conversions.

Bruce
 
R

Randy Webb

Bruce said:
Thanks guys...

Yes, "line-height" accomplished what I need. Not exactly as I had in
mind but since it limits the expansion of the row, it's good.

Just curious now, since it no longe matters, but what would be the
better way of solving my original problem of the user changing the size
of font he sees??

Redesign your site so that it scales no matter how I have my fonts set.

Personally, in IE6, I have your font definitions explicitly disabled so
that its set the way *I* want them.

Tools>Internet Options>Accessibility
 
R

RobG

Bruce said:
Thanks guys...

Yes, "line-height" accomplished what I need. Not exactly as I had in
mind but since it limits the expansion of the row, it's good.

Just curious now, since it no longe matters, but what would be the
better way of solving my original problem of the user changing the size
of font he sees?? What about getting the font's attributes, as you can
[...]

This would be better answered at:

comp.infosystems.www.authoring.stylesheets

However, since you are here now... if you use "em" as your units,
everything will be sized according to the font size. As the user
increases the size of their font, so too will all the elements based on
the font. It also means things in your page will scale as you change
fonts in your styles.

In regard to the lineHeight value of the element style property, if you
specify your element height as a multiple of lineHeight, the element
will scale vertically with the font - sometimes it works to specify
height as a multiple of lineHeight and width in pixels so your
elements don't scale off the sides of the screen but do grow taller to
accommodate bigger fonts.

Naturally, there are pros and cons for everything, have a play and see
if it does something for you.

Have fun.
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top