Results 1 to 3 of 3

Thread: define margin using pixels or percent?

  1. #1
    Join Date
    Mar 2012

    define margin using pixels or percent?

    Hi there! This is my question.

    Let's say I have two divs, div1 and div2. To define the top margin of div2 respect div1, I can do it in two ways using css.


    What's the best way to do it?? I am sorry because I know this is a stupid question, but I want to know the main differences between those two ways.

    Thanks a lot!

  2. #2
    Join Date
    Aug 2012
    It totally depends on if you want the top margin to always be 20px or if you want it to be 20% of the screen or containing div size.

    To throw something else into the mix, you could also use ems (based on your 20px, that would be 1.25ems).

    So basically do you want your top margin to be fixed or fluid / responsive (either way, use margin-top, not just top as that is for use with position: relative or position: absolute).

  3. #3
    Join Date
    Oct 2012
    Gujarat, India.
    Yup as simple as simplypixie said!

    I prefer Pixels more....and em is better then %.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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