Results 1 to 7 of 7

Thread: EM vs PX

  1. #1
    Join Date
    Jan 2008
    Location
    Portland, Oregon
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default EM vs PX

    When I 'google' the use of EM and PX measurement usage, I more or less only find the that EM is based upon the containers text size and and PX is more of a static sizing based upon pixels. Does anyone know of a web site that will help explain when it is appropriate to use EM over PX and vice versa? For instance, using EM measurement scale for a <div> background-image doesn't seem to be a good idea.
    Thank you in advance for your help

  2. #2
    Join Date
    Dec 2007
    Location
    Ankara, Turkey
    Posts
    160
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    I think this page would help

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by howellsgs View Post
    When I 'google' the use of EM and PX measurement usage, I more or less only find the that EM is based upon the containers text size and and PX is more of a static sizing based upon pixels. Does anyone know of a web site that will help explain when it is appropriate to use EM over PX and vice versa? For instance, using EM measurement scale for a <div> background-image doesn't seem to be a good idea.
    Thank you in advance for your help
    pixel's are based upon the browsers rendering engine and are absolute aka not resizable
    em's are based upon the dimensions of the M character of whatever font-family / size the browser is set at, and dimensions are reconfigured upon text-size increase / decreased by the user.

  4. #4
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi, even myself always get confused when to use EMs and px values. Correct me if I am wrong, now almost all the new versions of the browsers have an option to zoom the page if they feel font size is too small. The link provided in the first reply is useful in knowing what are the different ways of value asignment but is there a separate page dedicated which exactly tells you when to use which of the values? Thanks

  5. #5
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    There are very very few circumstances when I believe "pixels" are appropriate

    I tend to only use pixels if I am assigning a background image to a tag. in other words, I have a list and I want to apply a small icon to one of the sides to "dress" it up. Some developers would just embed the image right into the HTML, however the image is not essential, its a cosmetic improvement, therefore it's correct declaration is through css as a background image. Since I know the dimensions of the image I will be using, and I know they wont change unless I physically go in and change the the image itself, this would be an instance where pixels are the correct tool. As I said before, they are not subject to font size changes, where em's are. I apply a left padding to the element I want the icon to appear left of (or right padding if i want the image on the right) and then I apply the background image. Depending on the size of the image, you may also need to apply a line-height property to account for the full height of the element.
    Code:
    selector {
         padding: 20px;
         background: url('/path/to/image.gif') no-repeat top left/right;
    }
    If I use em's in this instance, if the user increases or decreases their font-size beyond a certain point the text will not display properly in relation to the image.

  6. #6
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    I ran across this article today and thought I would post it here. It seems to give a thorough explanation on EMs.

    I found that article in a disussion on the ExpressionEngine forums about this topic. People there have suggested several other websites/resources as a reference to using EMs. You can view that discussion here.
    Last edited by Medyman; 05-12-2008 at 11:58 PM.

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The answer to this is very simple:

    use pixels if you want a static size-- example: an image (you don't want your image resizing, do you?), or something like that.

    use em, %, etc. if you want something that fits the window, which is generally best for your overall design.

    Sometimes mixing is most effective, like having a 50px image in the middle of a 100% div, which means that there is 50%-25px left on each side, etc.
    (The math and layout can get complex, but for now just try to understand the concept-- the rest will come later!)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •