Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font-size that expands when you resize the window

How do I make my font in HTML such that when I expand the window, the size of the text expands also. Sort of like setting a percentage for the text that will take on a percentage of the size of the box it is in.

Here is an illustration of what I would like to happen:

#box #text {
   font-size: 50%;
}

Now lets say #box is 200px, #text should be 100px. Obviously I can't just put a fix width for #text because in the site #box will be a dynamic width.

like image 304
Chaim Avatar asked Jun 01 '11 20:06

Chaim


People also ask

How do you increase the font size that expands when we resize the window using jquery?

Do it in jquery. Show activity on this post. Use the vh (viewport height), vw (viewport width), and/or vm (viewport minimum (smallest of the dimensions)) units in browsers that fully support CSS3, and for other browsers listen for resize and JavaScript such as in Razor Storm's answer. That's awesome!

Which method occurs when window is resized?

The onresize event occurs when the browser window has been resized.

Which tag is used to resize the text?

In HTML, you can change the size of text with the <font> tag using the size attribute. The size attribute specifies how large a font will be displayed in either relative or absolute terms.


3 Answers

Do it in jquery.

$(window).resize(function(){
    $('#box #text').css('font-size',($(window).width()*0.5)+'px');
});
like image 100
Razor Storm Avatar answered Oct 17 '22 10:10

Razor Storm


Use the vh (viewport height), vw (viewport width), and/or vm (viewport minimum (smallest of the dimensions)) units in browsers that fully support CSS3, and for other browsers listen for resize and JavaScript such as in Razor Storm's answer.

like image 37
Eli Grey Avatar answered Oct 17 '22 08:10

Eli Grey


In browsers that support it, you can use CSS media queries to change your layout depending on the width of the window.

like image 1
Neil Avatar answered Oct 17 '22 10:10

Neil