vertical-align
is a strange CSS property. I added a border around the .inline
elements to show the effect.
The second div
is align centered to the baseline of the parent container. The first has implied vertical-align: baseline
and it adhers to that.
.content{
width: 100%;
height: 90%;
}
.middle{
position: fixed;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.menu{
width: 70%;
height: 80%;
}
.three {
width: 30%;
}
.six{
width: 60%;
}
.inline {
display: inline-block;
border: 1px solid;
}
.h-80{
height: 80%;
}
.h-100{
height: 100%;
}
<div class="content middle">
<div class="menu">
<div class="three inline h-80">
this is taking effect
</div>
<div class="six inline h-100" style="vertical-align: middle;">
while I inputing vertical align here
</div>
</div>
</div>
If I put vertical-align:middle
to both div
s you see, that the containers are both aligned centered, while the content of those div
s is not.
.content{
width: 100%;
height: 90%;
}
.middle{
position: fixed;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.menu{
width: 70%;
height: 80%;
}
.three {
width: 30%;
}
.six{
width: 60%;
}
.inline {
display: inline-block;
border: 1px solid;
}
.h-80{
height: 80%;
}
.h-100{
height: 100%;
}
<div class="content middle">
<div class="menu">
<div class="three inline h-80" style="vertical-align: middle">
this is taking effect
</div>
<div class="six inline h-100" style="vertical-align: middle;">
while I inputing vertical align here
</div>
</div>
</div>
You need to set the alignment of the content to center as well. This, alas, cannot be made done with the same technique. For this I would use flexbox with display: inline-flex; align-items: center
. For alternatives, take a look at this question: How do I vertically align text in a div?
.content{
width: 100%;
height: 90%;
}
.middle{
position: fixed;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.menu{
width: 70%;
height: 80%;
}
.three {
width: 30%;
}
.six{
width: 60%;
}
.inline {
display: inline-flex;
align-items: center;
border: 1px solid;
}
.inline span {
vertical-align: middle;
}
.h-80{
height: 80%;
}
.h-100{
height: 100%;
}
<div class="content middle">
<div class="menu">
<div class="three inline h-80" style="vertical-align: middle">
this is taking effect
</div>
<div class="six inline h-100" style="vertical-align: middle;">
while I inputing vertical align here
</div>
</div>
</div>
And to further adjust: You could drop the inline-block altogether and just use flexbox everywhere
.middle, .menu, .three, .six {
display: flex;
align-items: center;
}
.content {
width: 100%;
height: 90%;
}
.middle, .menu, .three, .six {
display: flex;
align-items: center;
}
.middle {
position: fixed;
justify-content: center;
flex-direction: column;
}
.menu {
width: 70%;
height: 80%;
}
.three {
width: 30%;
background-color: gold;
}
.six {
width: 60%;
background-color: silver;
}
.h-80 {
height: 80%;
}
.h-100 {
height: 100%;
}
<div class="content middle">
<div class="menu">
<div class="three h-80" style="vertical-align: middle">
this is taking effect
</div>
<div class="six h-100" style="vertical-align: middle;">
while I inputing vertical align here
</div>
</div>
</div>