I’ll explain the first problems, first vertical-align is used for siblings element and which are inline or inline-* (text type), div by default are block which is different from "text type".
In other words, you applied vertical-align expecting to affect block objects and that are father and son and not siblings, one way to use vertical-align would be this (this is not the solution is just to explain the vertical-align):
.irmao-1 {
background: #fc0;
height: 160px;
}
.irmao-2 {
background: #ccc;
height: 240px;
}
.irmao-1, .irmao-2 {
display: inline-block;
vertical-align: middle;
}
<div class="irmao-1">
Irmão 1
</div>
<div class="irmao-2">
Irmão 2
</div>
Another thing that seems to be confusing is the term background, the background only affects the element itself, each element will have its own background and the background property will never leak the element.
One thing, you don’t need to "fix" the height of all elements, you could use padding for example:
.pai {
background-color: #000;
padding-top: 20px;
padding-bottom: 20px;
}
.filho {
background-color: #ccc;
width:300px;
height: 240px;
}
<div class="pai">
<div class="filho">
oi
</div>
</div>
The sum of height: 240px with the padding-top: 20px and padding-bottom: 20px will make the parent element have 280px
An example with two Ivs:
.pai {
background-color: #000;
padding-top: 20px;
padding-bottom: 20px;
}
.filho-1 {
margin: 0 auto; /*centraliza horizontal*/
background-color: #ccc;
width:300px;
height: 240px;
}
.filho-2 {
margin: 0 auto; /*centraliza horizontal*/
background-color: #fc0;
width:300px;
height: 240px;
}
<div class="pai">
<div class="filho-1">
oi
</div>
<div class="filho-2">
oi
</div>
</div>
I don’t quite understand what you want to happen! I could explain better.
– Igor Mello