1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

What is an em?

Discussion in 'CSS' started by nevetS, Mar 23, 2005.

  1. #1
    Can someone please explain what an "em" is, and how it relates to other sizing things - like pixels.
     
    nevetS, Mar 23, 2005 IP
  2. palespyder

    palespyder Psycho Ninja

    Messages:
    1,254
    Likes Received:
    98
    Best Answers:
    0
    Trophy Points:
    168
    #2
    "em: the 'font-size' of the relevant font
    ex: the 'x-height' of the relevant font
    px: pixels, relative to the viewing device "

    Not sure what it stands for...
     
    palespyder, Mar 23, 2005 IP
  3. nullbit

    nullbit Peon

    Messages:
    489
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    em's are a contrived unit for CSS, they pretty much correlate to percentages:

    1em = 100%
    1.5em = 150%
    And so on..
     
    nullbit, Mar 23, 2005 IP
  4. Webnauts

    Webnauts Peon

    Messages:
    133
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Using ems, enhances your pages accessibility.
     
    Webnauts, Apr 8, 2005 IP
  5. SEbasic

    SEbasic Peon

    Messages:
    6,317
    Likes Received:
    318
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It makes no difference if you are already using a scaleable format like %, however if you are using px or pt or an unscalable format, it would make a massive difference to accessibility users.
     
    SEbasic, Apr 8, 2005 IP
  6. mcfox

    mcfox Wind Maker

    Messages:
    7,526
    Likes Received:
    716
    Best Answers:
    0
    Trophy Points:
    360
    #6
    mcfox, Apr 8, 2005 IP
  7. SoxFan

    SoxFan Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Another point about em is that it defines it's size from the parent element. So let's say you have your page and you set the body tag to have a font size of .9em, and then you set a p tag to have a font size of .5 em, the p tag will take 50% of the .9em and not 50% 1em.
     
    SoxFan, Apr 14, 2005 IP
  8. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Not quite, if I understand you correctly. em is defined as the font-size of the relevant font. font-size is described in CSS2 as

    In other words, if you change font-size for the current element, em will refer to the current element's font-size, not the parent's.

    J.D.
     
    J.D., Apr 14, 2005 IP
  9. SoxFan

    SoxFan Peon

    Messages:
    90
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    That is correct. There is one exception to that rule though. When an em is used in a "font-size", it becomes relative to the parent element. Here is the W3C spec:

    Here is an example of what I am talking about...

    http://limepudding.com/ems.htm
     
    SoxFan, Apr 14, 2005 IP