Reputation: 2344
I am trying to adjust text size so it can fill a certain space
For example : so, lets say that my HTML is like this :
<h1 style="width:120px;">some text</h1>
I want the word "some text" to fill the 120px automatically knowing that "some text" could be anything! I do not care if the font width is stretched or some spaces has been added to the word to make it fit the 120px width.
I know that in CSS we have overflow:hidden;
and overflow:scroll;
but those two will not help me with anything
overflow:hidden;
will hide any extra characters outside the 120px
overflow:scroll;
will make a scroll which I do not want !
any solutions? maybe a Jquery plugin or something? I have looked everywhere but I could not find anything.
Upvotes: 1
Views: 959
Reputation: 382122
You may adapt the font to the available space using such a script :
var fontSize = 100;
var reduce = function() {
$('#txt').css('font-size', fontSize);
$('#mes').html(fontSize);
if ($('#txt').width()>MAX_MIDTH) {
fontSize -= 1;
reduce();
}
};
reduce();
$('#width, #height').change(function(){fontSize = 100;reduce()});
Upvotes: 2