473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to get the height of a text line

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.
Jul 23 '05 #1
6 5692
On 10 Nov 2004 12:17:45 -0800, Bruce wrote:
...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.
That is encouraging..
..But how can I get the actual size they are seeing?


Why do you need to know? There is usually a more sensible
answer to the question than attempting to second guess any
aspect of the user's UA.

OTOH, there *is* always..
window.prompt("How many pixels?"); // ;-)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Jul 23 '05 #2
> 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
Jul 23 '05 #3
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #4
Bruce xxxxxxxx wrote:
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
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5
Bruce xxxxxxxx wrote:
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.
Jul 23 '05 #6
Thanks v much ... took a while to absorb but I got it.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Rithish | last post by:
If I have something like, <TABLE><TR><TD STYLE="'Font-Family:Arial'">Arial Text</TD></TR></TABLE> What would be the height of the cell? I believe it would be corresponding to the font used......
12
by: Stanimir Stamenkov | last post by:
Here are two cases regarding inline-level elements' line-height, padding and background, which I doesn't understand: <div style="background: black; color: white; line-height: 1.5">...
4
by: Stefan Krause | last post by:
If a line-height is defined for a text and an image (e.g. 9px wide and 7px high) is inserted the line-height will be altered (e.g 15 instead of 16 pixels) for IE 5.0, 5.5. and 6.0. Here's an...
3
by: Michael Goldbach | last post by:
Hi, I'm currently encountering a problem with vertical alignment of text in a DIV that drives me mad. I'm having a DIV with a fixed height (say 50px) which contains some text from which I...
4
by: Kourosh | last post by:
Is there a way to get the hight of text in a table using code?
1
by: Mike Collins | last post by:
I am trying to create some pages and have them take 100% of the window, but I cannot get 100% to work. If I set the height of my div, the page displays a scroll bar and it looks like I set the...
1
by: mascouta | last post by:
I have a lot of problems with IE browser, one of them is described in this topic. in my website i have div Calculator with background image. it displayed perfectly with Firefox browser however in IE...
5
by: Sal Monella | last post by:
At http://tides.org the (all caps) font on the top-row links on the various horizontally mounted dropdown menus appear abnormally tall and narrow to me. How do you do this? line height...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
2
by: ziycon | last post by:
I have the below code, when a user clicks on the <a href="#" onclick="showhide('languages'); return false;">Language(<div id="current_lang">en</div>)</a> it shows a DIV that is hidden and when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.