Do You Position with the Position Property or with Margin and Padding?

Discussion in 'CSS' started by Masterful, Oct 20, 2009.

  1. #1
    I tend to position elements using margin, padding and float. I don't usually use the position property, unless I want elements to overlap.

    Do you do the same?

    When are you supposed to use each of the different options?
     
    Masterful, Oct 20, 2009 IP
  2. cooldesign

    cooldesign Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Using Padding is the best solution to do this avoid using property to do the same this is not a good practice.


    Thanks
     
    cooldesign, Oct 20, 2009 IP
  3. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #3
    I use positioning in all situations. Padding/margin are not for positioning but are too give breathing room between elements.
     
    drhowarddrfine, Oct 21, 2009 IP
  4. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Interesting . . .

    Please elaborate a bit as to when you use each option.
     
    Masterful, Oct 21, 2009 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Your method is correct, positioning should only be used in select circumstances, for example with drop-down menus, or when you must position something relative to something else and a margin/negative-margin won't do the trick.
     
    wd_2k6, Oct 22, 2009 IP
  6. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I rarely use positioning. I push everyone to my will usually with margins and padding. And I float a lot.

    I'll use relative positioning more often to stabilise a page element for IE or for example a sticky footer (so floated children inside don't get lost). I use relative positioning a lot for setting new stacking contexts too.

    I'll use absolute positioning for small chunks of something where it's safe to state exactly where it needs to be in relation to a parent. wd mentions menus, that's one place I usually use it.

    So long as the design I'm using can work with divs acting naturally like soap bubbles who also have this preference for the left side, I can bump everyone into place without positioning. I'd use more positioning when I can be more certain of coordinates meaning the same thing per user.

    The doc might be referring to something like the Andy Clarke technique, which is using almost all absolute positioning. Google it, he's written a lot about it. Hasn't convinced me any, but I'm pretty sure I've seen some forms done with his style and it dealt well with text-enlarge and zooming.
     
    Stomme poes, Oct 24, 2009 IP
  7. adwebtiser

    adwebtiser Peon

    Messages:
    95
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I find it better to use margin & padding rather than position element specially when its for the right and left, since it will give different results on different browser resolutions!
     
    adwebtiser, Oct 28, 2009 IP
  8. casben79

    casben79 Guest

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    margin, padding and float for most things, positioning only when i need it... i avoid absolute as much as possible have had issues with it as margins dont work and it goes from the parent div that is absolute as well, if no parent is absolutely positioned, then it goes to the edge of the browser which is a sure fire way to royally screw with a layout.
     
    casben79, Oct 29, 2009 IP
  9. drhowarddrfine

    drhowarddrfine Peon

    Messages:
    5,428
    Likes Received:
    95
    Best Answers:
    7
    Trophy Points:
    0
    #9
    No. There are similarities, though, and I use ap whenever I feel like it. Many people use float anytime they want something along the left/right edge which, in many cases, is the wrong method. Like you, I let elements show in their natural position. Then I use positioning if necessary. I have no fear of absolute positioning and use it all the time.
     
    drhowarddrfine, Oct 29, 2009 IP
  10. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I'd be interested in seeing a complicated layout of yours with a lot of positioning, Doc. Like I said, I do remember seeing a form once done almost entirely in AP and it scaled well but it also seemed like a lot more code, which is another reason I usually do the floating rather than positioning: it feels like I'm spending a lot of time pinpointing where something should sit when generally-in-the-right-place usually does it for me, with margins for tweaking.
     
    Stomme poes, Oct 29, 2009 IP