473,474 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

dynamically determine the largest possible font size

hi all-

i'm a totally js hack so go easy on me...

i'd like to create a function that, given the size of a block of text
in

x = maximum number of chars
y = total number of lines (this is in chars too of course)

could determine and set the font size to be close, say 90 percent, to
the maximum that will display in the users browser without scrolling.
if you know what lightning slides are you'll understand what i'm
doing.

for example, given

foo
bar
foobar

x = 6
y = 3

i am trying to set the font size such that this text would __just__
fit onto the screen without scrolling in horizontal or vertical
directions.

i've got some code that's close, but i'm hoping someone here might
have a more elegant way.

kind regards

-a

Feb 6 '07 #1
1 1873

ar**********@gmail.com wrote:
hi all-

i'm a totally js hack so go easy on me...

i'd like to create a function that, given the size of a block of text
in

x = maximum number of chars
y = total number of lines (this is in chars too of course)

could determine and set the font size to be close, say 90 percent, to
the maximum that will display in the users browser without scrolling.
if you know what lightning slides are you'll understand what i'm
doing.

for example, given

foo
bar
foobar

x = 6
y = 3

i am trying to set the font size such that this text would __just__
fit onto the screen without scrolling in horizontal or vertical
directions.
Hi,
You can try to define max font size for the container by augmentation
in series until the container size exceeds the document body size. For
example, code snippet(untested):

function getFontSize()
{
var s = document.getElementById("container");
var fontSize = 10;
while(true)
{
s.style.fontSize = fontSize;
if (s.offsetWidth document.body.offsetWidth || s.offsetHeight
document.body.offsetHeight)
{
fontSize--;
alert("Max font size = "+fontSize);
break;
}
fontSize++;
}
}

It is simple an idea.
i've got some code that's close, but i'm hoping someone here might
have a more elegant way.
You didn't post the code you have, so I could not compare elegancy. :)

Feb 6 '07 #2

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

Similar topics

3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
1
by: Timo | last post by:
All my font-sizes are set as relative sizes in CSS (large, medium, small, x-small, etc). Let's say something is set in CSS to be xx-large, but a visually impaired user wants it displayed even...
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
2
by: strauchdieb | last post by:
hey everyone i try to figure out how to calculate string width in a textarea while typing in it. the textarea has a fixed start width. when the string gets longer as the textarea width, the...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
30
ADezii
by: ADezii | last post by:
This week’s Tip of the Week will clearly demonstrate how you can dynamically set the Drop Down List Width of a Combo Box to the length of the longest item in its Row Source. The inspiration for this...
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.