I've got two div elements with my classes container and innercontainer with the following CSS styles.
.container {
width: 200px;
height: 200px;
background-color: green;
}
.innercontainer {
height: 30px;
background-color: red;
margin: auto;
margin-top: 80px;
}
<div class="container">
<div class="innercontainer"></div>
</div>
What I expected was a red rectangle almost in the center of a green square.
What I got was a red rectangle on top of a green square. It shifted my rectangle 80px down but why does it put my square below the rectangle?
If I put a border around the square everything goes as expected. The same is if I say position: fixed
in my container class.
I thought block elements orient themselves at the border of their surrounding container. In this case it seems to me as if innerconainer orients itself at the body?