It is probably would be the simplest of task, and yet I am unable to understand. I created a very simple HTML Snippet. Code Pen Link
If you see the the pen, I have 3 nested divs, div1
being the top level div for my React Application. Now my page’s body is pink color
. I added a div => header
and one more div => logo
. Now my header div is green color
. So far, so good, now in my logo div, i have an img
tag. I didn’t like the positioning of my image and added margin-top
to my logo div. My intention was, that the my logo div should put a margin from the top of header div which is green. But instead, it inserted a margin between my body top and my header div.
I am totally running out of ideas why this is so? Any help?
2
Answers
#logo has a margin that goes beyond the parent element. See if this can help you -> CSS margin terror; Margin adds space outside parent element