Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font size relative to the user's screen resolution?

I have a fluid website and the menu is 20% of its width. I want the font size of the menu to be measured properly so it always fits the width of the box and never wrap to the next line. I was thinking of using "em" as a unit but it is relative to the browser's font size, so when I change resolutions the font size stays the same.

Tried also pts and percentages. Nothing works as I need it...

Give me a hint of how to proceed, please.

like image 669
barakuda28 Avatar asked Aug 02 '12 12:08

barakuda28


People also ask

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.

Does screen resolution affect font size?

The monitor is manufactured with a specific arrangement of pixels, which is its "native" resolution. Characters are drawn on the screen by defining which pixels are illuminated within an imaginary grid. The number of pixels in the grid determines the size of the font on that monitor.

What is font size relative to?

For most font-relative units (such as em and ex ), the font size is relative to the parent element's font size. For font-relative units that are root-based (such as rem ), the font size is relative to the size of the font used by the <html> (root) element.

Is font size relative to page size?

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.


2 Answers

You can use em, %, px. But in combination with media-queries See this Link to learn about media-queries. Also, CSS3 have some new values for sizing things relative to the current viewport size: vw, vh, and vmin. See link about that.

like image 117
Miljan Puzović Avatar answered Sep 28 '22 06:09

Miljan Puzović


New Way

There are several ways to achieve this.

*CSS supports dimensions that are relative to viewport.

  1. 3.2vw = 3.2% of width of viewport

  2. 3.2vh = 3.2% of height of viewport

  3. 3.2vmin = Smaller of 3.2vw or 3.2vh

  4. 3.2vmax = Bigger of 3.2vw or 3.2vh

    body {     font-size: 3.2vw; } 

see css-tricks.com/.... and also look at caniuse.com/....

Old Way

  1. Use media query but requires font sizes for several breakpoints

     body  {      font-size: 22px;   }  h1  {     font-size:44px;  }   @media (min-width: 768px)   {     body     {         font-size: 17px;      }     h1     {         font-size:24px;     }  } 
  2. Use dimensions in % or rem. Just change the base font size everything will change. Unlike previous one you could just change the body font and not h1 everytime or let base font size to default of the device and rest all in em.

  • “Root Ems”(rem): The “rem” is a scalable unit. 1rem is equal to the font-size of the body/html, for instance, if the font-size of the document is 12pt, 1em is equal to 12pt. Root Ems are scalable in nature, so 2em would equal 24pt, .5em would equal 6pt, etc..

  • Percent (%): The percent unit is much like the “em” unit, save for a few fundamental differences. First and foremost, the current font-size is equal to 100% (i.e. 12pt = 100%). While using the percent unit, your text remains fully scalable for mobile devices and for accessibility.

see kyleschaeffer.com/....

like image 42
aWebDeveloper Avatar answered Sep 28 '22 08:09

aWebDeveloper