How font size works in CSS?

This is a discussion on "How font size works in CSS?" within the Web Page Design section. This forum, and the thread "How font size works in CSS? are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Dec 2nd, 2005, 15:08
New Member
Join Date: Dec 2005
Location: UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
How font size works in CSS?

Hi All,

This must be the very simple question for all there.

If I set size for <h1> using

h1 {font-size: 1em}

then try displaying a h1 text. It is displayed as normal text not as default h1 font size of browser? Why as 1em means relative to default of browser?


Thanks in advance for spendinf time on this very simple question.
Reply With Quote

  #2 (permalink)  
Old Dec 2nd, 2005, 22:14
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

1em = 100% the size of the parent font
.5em = 50%
1.5em = 150% etc
Reply With Quote
  #3 (permalink)  
Old Dec 12th, 2005, 20:49
Junior Member
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Hi,

Just a handy little note but I believe that most browsers have a default size for 1em = 16 pixels (approx).

When using em's you should really set the body font-size to 100%:
eg body {font-family: verdana, ariel, sans-serif; font-size:100%;}

Gecko.
Reply With Quote
  #4 (permalink)  
Old Dec 12th, 2005, 21:23
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

That is not how em works at all...
em defines the text size in relation to the font size of the parent element.
Reply With Quote
  #5 (permalink)  
Old Dec 18th, 2006, 18:20
Up'n'Coming Member
Join Date: Jun 2006
Location: Northern Ireland, United Kingdom
Age: 22
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Antwan
Re: How font size works in CSS?

Quote:
Originally Posted by Pheonix View Post
That is not how em works at all...
em defines the text size in relation to the font size of the parent element.
Correct, and I think the overall em is based on your browsers default font size
Reply With Quote
  #6 (permalink)  
Old Dec 18th, 2006, 19:47
Reputable Member
Join Date: Jul 2006
Location: Scotland
Age: 22
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to snow
Re: How font size works in CSS?

em is based on the width of the capital letter 'M' of the parent font...

so 1em is one 'M', .5em is half that size as pheonix said.
Reply With Quote
  #7 (permalink)  
Old Dec 18th, 2006, 21:11
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: How font size works in CSS?

You will find what you need to know about ems if you look in the sticky at the top of the css forum.

Edit: This sticky is entitled, 'CSS query - start here'.

Why does nobody seem to understand this?
Reply With Quote
  #8 (permalink)  
Old Dec 18th, 2006, 21:25
Reputable Member
Join Date: Nov 2006
Location: London, England
Age: 15
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Dapandyman
Re: How font size works in CSS?

lol i have done that so many times...... i go to that first now
Reply With Quote
  #9 (permalink)  
Old Dec 19th, 2006, 01:01
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

This thread is a year old o.O I don't understand why its been brought back
Reply With Quote
  #10 (permalink)  
Old Dec 19th, 2006, 01:17
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

It's a ghost.
Reply With Quote
  #11 (permalink)  
Old Dec 19th, 2006, 04:59
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

/calls an exorcist
Reply With Quote
  #12 (permalink)  
Old Dec 19th, 2006, 10:32
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Oh no! Not one of them!
Reply With Quote
  #13 (permalink)  
Old Dec 19th, 2006, 10:33
Daniel's Avatar
Elite Veteran
Join Date: Sep 2006
Location: The Kingdom of Rabbits
Age: 21
Posts: 2,051
Blog Entries: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Daniel
Re: How font size works in CSS?

wooooooooooooooooooooooooooooooooooooooooooooooooo ooooooooooooooooooooooooooooooooooooooooooo
Last Blog Entry: Assassin's Creed (Nov 22nd, 2007)
Reply With Quote
  #14 (permalink)  
Old Dec 19th, 2006, 14:01
moojoo's Avatar
Moderator
Join Date: Aug 2005
Location: Texas
Age: 31
Posts: 1,761
Blog Entries: 1
Thanks: 0
Thanked 18 Times in 18 Posts
Send a message via AIM to moojoo Send a message via MSN to moojoo Send a message via Yahoo to moojoo
Re: How font size works in CSS?

0.9em is a good general font size with 0.85em or so for large scale fonts such as verdana.
__________________
The internet is just a fad.
http://www.mevans76.com
Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Reply With Quote
  #15 (permalink)  
Old Dec 19th, 2006, 14:50
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

I've heard a lot of controversy over this, but do you think it's bad to declare font-size: 70%; in the body tag? It makes it way easier to use intergers for paragraphs and headers.
Reply With Quote
  #16 (permalink)  
Old Dec 19th, 2006, 15:01
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: How font size works in CSS?

I believe the size you set in the body tag should be the default size for your site.

Coupled with the fact the the end-user has the option in their browser (well in any decent browser) to set both the normal and minimum font size, this default should represent 1em but set as a percentage - see sticky.
Reply With Quote
  #17 (permalink)  
Old Dec 19th, 2006, 15:20
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Er. I'm confused. When you say "1em but set as a percentage," that should just be 100%... As for the sticky, I don't see anything relevant to what I was trying to say.
Reply With Quote
  #18 (permalink)  
Old Dec 19th, 2006, 15:23
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: How font size works in CSS?

I was referring to setting the body font size to 100.01% because of a quirk in IE.
Reply With Quote
  #19 (permalink)  
Old Dec 20th, 2006, 01:30
Ryan Fait's Avatar
SuperMember

SuperMember
Join Date: May 2006
Location: Las Vegas
Posts: 3,786
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How font size works in CSS?

Does using 70% fix the quirks? I'm having a hard time finding detailed information on the bug.
Reply With Quote
  #20 (permalink)  
Old Dec 20th, 2006, 22:56
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
Re: How font size works in CSS?

Here is one reference:
http://css-discuss.incutio.com/?page...xplorerWinBugs

Google with '+IE +font +sizing +bug +100%' will get you quite a few more.
Reply With Quote
Reply

Tags
font, size, works, css

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Ideal Font / Size? sing2trees Web Page Design 12 Dec 28th, 2007 09:50
IE7 font size and formatting - help Xhristy Web Page Design 4 Apr 3rd, 2007 17:35
Best way to define font size? rubyfruit Web Page Design 11 Sep 13th, 2006 13:58
why h1 doesn't inherit font -size from body? sahota Web Page Design 3 Dec 12th, 2005 20:55
font-size: does not work in <body> andersonoo7 Web Page Design 4 Jul 23rd, 2005 03:00


All times are GMT. The time now is 07:53.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43