Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS problem assigning font size value em for html element

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #41336
    prathoven
    Participant

    Hi, everyone

    I’m stucked in the wierd problem. I google it but can’t find solution. Here’s the problem:

    http://jsfiddle.net/prathoven/dm4Dk/

    If px is assigned it works. I’m stuck here with curiosity. Thanx.

    #117368
    Paulie_D
    Member

    You are encountering the fact that the size ’em’ inherits its base size from the parent, in this instance the li.

    Thus in your example, the size is 1.8×1.8 which = 3.24? [or is it 1.8+0.8=2.6?? I always get confused]

    See: http://jsfiddle.net/tvgbW/1/

    #117369
    David_Leitch
    Participant

    The unit of measure em is calculated on the selector’s parent element. Therefore ul li is 1.8 times the base font and ul li em is 3.24 times the base element, because it’s 1.8 * 1.8 (ul li’s font-size).

    To solve this, you can either use rem, which is based on the root element (so, the html or body font-size), or you can set ul li e to 1em.

    Sorry if my explanation is a bit confusing :)


    @Paulie_D
    Too fast for me :D

    #117371
    Paulie_D
    Member

    @David_Leitch No problem, of course rem is the answer but browser support is [very limited](http://caniuse.com/#search=rem “very limited”) [IE9+] at the moment AFAIK.

    #117373
    David_Leitch
    Participant

    I was thinking that rem support was a bit limited, but couldn’t remember how much so; thanks for the link :)

    Just out of interest, do you think it’s still worth the time to use rem, with em fallback, despite the limited support? i.e.:

    ul li{
    font-size: 1.2rem;
    font-size:1em;
    }

    Or should it be something to keep in mind, but wait until more widespread support?

    #117375
    Paulie_D
    Member

    >Or should it be something to keep in mind, but wait until more widespread support?

    I think this purely because I don’t want to set two properties every time at the moment.

    However, if you wanted to future-proof then there is no reason you couldn’t use both now (of course the rem setting should be after the em setting….no?).

    Personal choice I guess.

    #117378
    David_Leitch
    Participant

    Ah yes, sorry. Had meant to put them the other way round; blame it on trying watch a movie at the same time as typing :)

    Good point, @joshuanhibbert

    #117379
    Paulie_D
    Member

    Ah…multi-tasking. :)

    #117495
    prathoven
    Participant

    Thanx all for helping me figuring it out.
    So the buttom line is font size of for <.em> here is double of parent of li.

    I think i won’t use rem because its not widely supported and moreover to save few bytes!

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘CSS’ is closed to new topics and replies.