Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using percent for font size?

Tags:

css

font-size

I've read a fair bit about resizing fonts recently, most of it deriding using px as an unforgivable crime (ok, maybe not that bad, you get the idea) because it doesn't resize properly in older browsers.

I really want to have a standard that I use myself, in the past that has been px, simply because it's simple, easy to understand and fairly easy to achieve the exact font sizes that are specified in designs - but I'm now doubting using px.

I used em on a project recently because it needed text-resizing functionality which I made using jQuery. But I found it quite frustrating because of the way that em amplifies if you have two elements inside of each other both with an em size specified (hope that makes sense)

So I was wondering about using % for font resizing, I've seen a couple of big websites use this technique (namely, Yahoo) and from what I understand it seems to have all of the advantages of em without the incredibly annoying amplification thing.

So in short, I'm just wondering if there are any issues with using % for font-sizing in CSS? Would it be better than using PX in terms of font-resizing? And are there any noticeable draw backs?

Apologies if the blurb before the question is a little much :/ I'm still kind of getting used to the whole QA thing

like image 265
Sean Avatar asked Apr 25 '12 21:04

Sean


People also ask

Can you use percentages for font size?

font-size can accept keywords, length units, or percentages as values. It's important to note however that when it's declared as part of the font shorthand property, font-size is a mandatory value.

How do you calculate font size?

A font is often measured in pt (points). Points dictate the height of the lettering. There are approximately 72 (72.272) points in one inch or 2.54 cm. For example, the font size 72 would be about one inch tall, and 36 would be about a half of an inch.

Can we give font size in percentage in HTML?

If you have two div elements, one within the other, each with a font-size: 110% then that'll be calculated exactly the same as a font-size: 1.1em .

What units should I use for font size?

Using em Units A more suitable CSS unit for font sizes is the em. The em is a scalable unit, 1em is equal to the current font size; so if the parent's font size is 16px, 1em is 16px and 2em is 32px.


1 Answers

In CSS3, use rem (root em). Sizing will not be affected by em size of the parent element.

The root font size is set by setting the font size on the :root pseudo-element, like so:

:root {     font-size: 16px; } 
like image 194
Richik SC Avatar answered Sep 26 '22 04:09

Richik SC