Reputation: 19896
I would like to display a single line of text across the screen so that:
Width:
100%Fonts-size
is maximum possible based on browser widthnowrap
)font-family
My idea is to start a hidden div
and random font-size
, then run jQuery to "brute force" to increase or decrease font-size
so that its width is close to browser width.
Is there a best way to do this? Great if I can see some examples. Thanks.
Upvotes: 2
Views: 1972
Reputation: 19896
This is the solution
http://simplefocus.com/flowtype/
$('body').flowtype({
minimum : 500,
maximum : 1200
});
Download https://github.com/simplefocus/FlowType.JS
Web typography at its finest: font-size and line-height based on element width.
Upvotes: 2
Reputation: 10228
I would figure out how wide the text is as a ratio to the height of the font, then do something like
var w = [parentElement].clientWidth;
[textElement].style.fontSize = w*ratio;
Upvotes: 0