How to make font-size change depending on string length?
I have a table:
<table width="200px">
<tr>
<td>
<font style="font-size:14px;"><?php echo $text; ?></font>
</td>
</tr>
</table>
The $text variable is dynamic, and might be 3 characters long, or 50 characters long.
The problem is the width of the table colum开发者_StackOverflow社区n is limited to 200px.
How can I make the text always fit on one line, and preserve the limited width of the table?
I am looking for something like a dynamic font-size function? Or any other (good/easy) way?
Thanks
The solution in Auto-size dynamic text to fill fixed size container seems like it would work for you, if you're using jQuery that is.
Using Mootools you can basically measure an Element size.
I think that if you create a dummy element in the DOM (positioned outside the screen view) containing the text you need to insert. Then you can cycle the font size until you find the dimension that fit you're table width.
A little bit dirty ...
EDITED: same approach, but in jquery, is used by miket2e answer link
精彩评论