Is it possible to adapt font size to div width?
# February 17, 2011 at 1:26 pm
I have some div with 250px width and 500px height and here’s what i want to do:
– put some words in that div with br’s next to it
– adapt font size so that those words occupy all div width (bigger words with small font size and vice versa)
Is this possible with only css? If not, is it possible with anything?! :p
Thanks in advance!# February 17, 2011 at 5:20 pm
i.e: (div width/span width) * span font-size# August 29, 2011 at 12:23 pm
Thanks Johnnyb for that snippet. Thought I share a tiny deviation for the following scenario:
Want text to scale div stretching entire browser window. Want 250 px margin for picture.
note: had to use $(window).load … otherwise the resize did not happen (guess a sequence problem) *shrugs*# October 17, 2012 at 8:05 am
If find this topic is interesting so I decided to give it a shot, but I’m having some trouble. Anyone wanting to check my code and see if you can figure out what’s wrong?
parentW = elemToR.width();
curRow = $(this);
curWidth = curRow.width();
var ratio = parentW / curWidth;
$(this).css(‘font-size’, ratio * initialSize + ‘px’);
initialSize = 10;
You must be logged in to reply to this topic.