Converting to em's (Full Version)

All Forums >> [Web Development] >> Cascading Style Sheets and Accessibility



Message


davidrandall -> Converting to em's (6/9/2006 10:42:02)

Wasn't sure whether to put this here or in accessibility as it covers both.

I always use a relative font size (that can be scaled) on my sites which poses a problem when a client sends their brand guidelines with fonts specified in pixels or points.

This makes using percentages very difficult for font sizes as it's pretty much trial and error to see what looks right. For this reason I now use em's.

Ems are relative to the font size defined in the parent container or, if there isn't one, the browser's default. Therefore 1em is equivalent the the base font size. 2em is twice that size.

As a default, a browser's font size is set at 16px so 1em = 16px. That's not a very managable number so I set the base font size to 10px.
10px/16px = 0.625 so 10px is 62.5% of 16px


I set the font size on the <body> tag to 62.5%. This makes the default font size for the website equivalent to 10px.

1em now equals 10px, 1.6em = 16px and so on.

Dave




jaybee -> RE: Converting to em's (6/9/2006 10:49:38)

Thanks David, I think my brain has coped with that but I was under the impression that 16px in one browser is a different size to 16px in another browser so how do we get round that one?




caz -> RE: Converting to em's (6/9/2006 14:33:25)

Previously in loads of discussions about this issue some relevant sites are always mentioned, see this post in the sticky above.

http://www.frontpagewebmaster.com/m.asp?m=259135&mpage=1&key=




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875