1

I was thinking, about how the margin influence other objects?

Because when I have e.g.

html, body{
    height: 100%;
    width: 100%;
}
div{
    margin-top: 200px;
}

and inside I have div with margin-top it push <body> down, so the margin impact on <html> not on <body> tag, which is first container.

So the question is, how margin depend on

  1. parent tag
  2. siblings tags
  3. floating, absolute, relative or static elements

I have readed few css tutorials, but I couldnt find specific answer

Kornel Dylski
  • 1,233
  • 14
  • 17

1 Answers1

1

Most browsers by default add a margin to the <body> element. One thing you haven't done in your styling is to reset this to 0:

html, body{
    height: 100%;
    width: 100%;
    margin: 0;
}

Why this happens is a question that has been asked many times here. See: What is the point of CSS collapsing margins? and Why does this CSS margin-top style not work?.

Community
  • 1
  • 1
James Donnelly
  • 126,410
  • 34
  • 208
  • 218
  • I noticed that, but body margin is only about 20px, (I set 180px more) and the same is happening when I have wrapper div instead of body. Anyway, collapsing margins is right answer, Thank You. – Kornel Dylski Aug 05 '13 at 10:12