SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Margins px vs %- which one?

    As I am trying to learn CSS, I am looking at lots of peoples code, and see both px and % used for margins. When I experiment with CSS myself, I sometimes end up using both px and % for my margins as well....
    Is this bad form to have them both mixed in your CSS?
    Is there a general rule or preferance on using px or % when defining margins?

    Thanks for your input

  2. #2
    SitePoint Wizard rbutler's Avatar
    Join Date
    Jul 2003
    Location
    Springfield, MO
    Posts
    1,867
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    px are fixed width. Meaning if you give your body a margin left and rigth of 20 px, you get just that. % in margins give you screen proportion. Meaning if you give your body a margin left and right of 20% percent, the browser will compensate for whatever resolution you are on. From what I know, it doesn't matter if you intermix them. You could give your body left and right of % and a paragraph later down the road a margin left of a specified amount in pixels.
    Ryan Butler

    Midwest Web Design

  3. #3
    Caveat surfer Buddy Bradley's Avatar
    Join Date
    May 2003
    Location
    Cambridge, UK
    Posts
    2,366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't matter if you mix and match, although you might get odd results at very large or very small resolutions. It's better to be consistent, though, so choose what works best for you and stick to it.


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
  •