What Does *{margin:0;padding:0;} Actually Reset?

Discussion in 'CSS' started by wd_2k6, Oct 26, 2008.

  1. #1
    Hi,

    The questions in the title basically, when using:

    * {
    margin:0;
    padding:0;
    }

    At the start of your stylesheet, what actually are you resetting here, and does it cause any problems I should be aware of?

    Would you reccomend using this or just stating the margins and paddings if I come to use an element in question which has odd defaults.
     
    wd_2k6, Oct 26, 2008 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    It set margins and padding on every element to zero. That means even the normal things like the space between paragraphs, or the indentions on lists and blockquotes are gone.

    It is, I think, a waste of bits. There are very few elements that different browsers treat differently enough to worry about. In most cases the default values are well chosen. In cases where they're not, you'd set your own values anyway. The reset would be superfluous.

    cheers,

    gary
     
    kk5st, Oct 26, 2008 IP
  3. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #3
    Yes, on forms. And it's irreversible. If you are just doing a demo for something then it's fine to use as there won't be any forms.

    I use both a reset and "reset-less" stylesheet just depending on the project. It is quicker to have the reset as you don't wonder "hmm why's that 10px out" or whatever when you're viewing it in IE compared to FF (not that IE is doing it wrong, just some different default values) and have to troubleshoot whether its bottom margin/padding or something, or top margin/padding on something else.

    For example, you may only style a H1 and H2 in accordance with the design. The person may add a H3 later and there's huge margin & padding on it and they wonder why. So without spending time styling everything, it's easier just to have everything reset to 0 so that if they add something without a style it will be "reset" as such and they only have to add what they want, not negate anything.

    Most of the beliefs with "resets" is that people use them when they suck, and as they get good they still use them remembering how hard to code it was without them (which is more because they sucked then they didn't have a reset)
     
    rochow, Oct 26, 2008 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    Without having the reset, they''d do the same thing; add the margin(s) they want. Having it zeroed first is no benefit.

    cheers,

    gary
     
    kk5st, Oct 26, 2008 IP
  5. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #5
    They'd have to remove the margin and padding. For example with headings, there is already margin on the p (that I set - margin:0 0 1em) so they don't need anything.
     
    rochow, Oct 26, 2008 IP
  6. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for the replies, i'll just continue as i'm doing without the reset and set values when required!
     
    wd_2k6, Oct 27, 2008 IP
  7. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It's just the padding that kills teh formz. If I haz teh forms, I reset margins like normal and padding on blocks only.

    * {
    margin: 0;
    }

    html, body, div, p, form, fieldset, whatever else is on the site {
    padding: 0;
    }

    I used to have margin: 0; padding: 0 on so many things... I like being able to set it in a single line to 0.

    If you're setting the margins on stuff though, as Gaary said, you're repeating yourself. I usually set margins on h1's and h2's so I really don't need to set them to 0 first-- however I don't set them on other headers usually so I like the reset instead of 0, 0 set manually on everything.

    If the design isn't exacting you won't see the defaults too much, but if the person who set the design is picky, it's just easier to start at zero and build up what you need.
     
    Stomme poes, Oct 27, 2008 IP
  8. justinlorder

    justinlorder Peon

    Messages:
    4,160
    Likes Received:
    61
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You should learn the three box model.
    margin is the most out box, the border is the middle of the box and the padding is the inner box .
    Learn from here. http://www.w3.org/TR/CSS2/box.html
     
    justinlorder, Oct 27, 2008 IP