Here's one I've never encountered before. Is it possible to make a font scale with the window size of the browser. For example: making the font size 100% of the available width. I'm open to Javascript, jQuery or CSS solutions.
-
There is an article and demo about this at - [Dynamic Page Sizing - A Javascript Solution](http://countjustonce.com/flag/flag_strict.html) and related: - [CSS: How to scale entire web page with CSS?](http://stackoverflow.com/questions/1156278/css-how-to-scale-entire-web-page-with-css) – Gordon Jul 29 '10 at 15:02
2 Answers
What do you mean by "font size 100% of the available width"? That your font size, in pixels, will be equal to the width, in pixels, of the page, or if some text will fill the width of a page?
First case: font-size equal to page width
If you can use JavaScript, you can listen to window size change event, then to change the font size each time the window size is changed. You can do it either in plain JavaScript or in JQuery, whatever you are familiar with.
Second case: the width of a text equal to page width
This one is quite impossible to implement easily, since different browsers have different layout options, also affected by accessibility settings for each user. What you may try to do is to adjust the font size inside a <div/>
, measure the width of the <div/>
and readjust the font size until you get the width you want.
Of course, at least you have a few days to spend at optimizing the thing, this will give a terrible visual effect. To reduce it, you can adjust text on background (an invisible text), find the font size/width you want, then apply it to a visible block.

- 50,338
- 35
- 112
- 199
I don't see why you couldn't. Just create a JS handler for the window resize event and change the style.fontSize property of the targeted element in the handler function. So, something like:
window.onresize = function(event) {
document.getElementById('targ').style.fontSize='10';
}

- 1,451
- 1
- 12
- 25
-
Not sure that setting the font size to 10 will make "the font size 100% of the available width". – Arseni Mourzenko Jul 29 '10 at 15:05
-
I am not sure what the poster's statement about 100% entailed, but you could easily write a switch statement that adjusted font size according to window size. – Antony Jul 29 '10 at 19:02