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.

Using em and percent in css

Discussion in 'CSS' started by JimmyRP, Feb 18, 2012.

  1. #1
    So I am going with an entirely fluid layout, using only pixels for min-max values. I am not sure about the use of em vs. percentages, and how they relate to scaling. Currently, I am using em for margins, font sizes, and general spacing issues. I am using percentages for the width of the divs. So, is there a 'best practice' on what I should be doing about this. Should I use all em or all percents? If anyone could point to an article or two that deals with this it would be appreciated. Thanks!
     
    JimmyRP, Feb 18, 2012 IP
  2. nemanja.todic

    nemanja.todic Well-Known Member

    Messages:
    69
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    130
    #2
    In my opinion you're got it right. Use percentages for width of elements, em for margins, padding, font sizes etc.
     
    nemanja.todic, Feb 21, 2012 IP
  3. cssbros

    cssbros Member

    Messages:
    76
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    43
    #3
    Em and % are better than px.
     
    cssbros, Feb 21, 2012 IP
  4. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #4
    You may want to use css media selectors to create multiple fixed size layouts depending on available area, a good example of this is available at getskeleton.com

    Ultimately, it's all a matter of personal preference, the various units in CSS are just tools to do the job at hand - just remember to keep usability, cross browser functionality, and accessibility at the top of your consideration list, and you'll be fine.
     
    blacknet, Feb 22, 2012 IP
  5. IDocXD

    IDocXD Member

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    px is best for fixed layouts

    % and em is best for fluid layouts

    But yes yo have got the concept down pat. Just make sure you keep padding and margining in mind. Fluid layouts cause for a little bit of math or good ol trial and error.
     
    IDocXD, Feb 23, 2012 IP