Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set font-size relative to page size?

Tags:

html

css

Is there a way to make font-size relative to the size of the page? Applying percentage as unit refers to the standard font size (like 90% of 12px, not 90% of the page!). This is different from the behaviour of most of the other tags.

Any way to make the page 'scale up and down' also with fonts? Should I rely on em?

Thanks

like image 381
pistacchio Avatar asked Jul 25 '09 09:07

pistacchio


People also ask

How do I set relative font size?

It is related to the font size of the parent container. One em (1em) is equal to the current font size. So for example, if the parent element has the font size of 16px than 1em is equal to 16px, 2em is equal to 32px, and so on. Making your design responsive becomes much easier if you use em units instead of px.

How do I change the font size based on screen resolution?

Select 'Display'. Select the 'Change display settings' link towards the top of the window on the left-hand side. In the 'Resolution' section, select the pull-down bar, and a slider bar should appear. Move the slider bar down to make the text larger, or move it up to make the text smaller.

How do I apply a font family to a whole page?

Add the CSS * (asterisk) selector to select all the elements of the document. Set the font-size, font-family, line-height, and color properties.

How do I automatically adjust font size in HTML?

Syntax: font-size-adjust: number|none|initial|inherit; Below are the examples that illustrates the use of font-size-adjust property.


2 Answers

See the new vh and vw CSS units. Browser support isn't great yet.

http://snook.ca/archives/html_and_css/vm-vh-units

It landed in WebKit recently: https://bugs.webkit.org/show_bug.cgi?id=27160

In browsers that support it, 1 vh is 1% (1/100) of the viewport height, and 1 vw is 1% (1/100) of the viewport width. There are also vmin and vmax units, which represent the smaller of the two and the larger of the two, respectively.

like image 153
zachleat Avatar answered Oct 15 '22 00:10

zachleat


No you cannot set the size of the font in a percentage relative to the size of the page.

Sizing in em is based on the size relative to how the font would normally render in 16 point.

If you'd like your page to scale up and down and keep some sort of scale to itself, the boxes and the font, then setting it out in em would be fine.

That method will allow for the scaling of fonts and boxes of the page to grow at a relative size to one another and hopefully not have things falling out of bounds and borders.

like image 21
random Avatar answered Oct 15 '22 00:10

random