If we have two elements next to each other with display as inline-block, the bigger block (in terms of height) is the one which appears to influence the position of the other one when vertical-align is set for either of two.
How does it actually work? How can we think of a line on which an element will reside and when the vertical align is changed, we may just think it’s moving with respect to that line. Somehow I’m unable to understand why the other element also appear to move.
I'll illustrate with some examples. So Going through this link (with which this question has been marked duplicate) I did understand the the first div sets the baseline of the inline-block. for e,g in the following code, gjpiy sets the baseline and the other two inline-block divs that follow after that reside above this line.
.first, .second{
width: 100px;
display: inline-block;
}
.first{
height: 100px;
background: red;
}
.second{
height: 30px;
background: yellow;
}
.simpleDiv{
display: inline-block
}
<div class="simpleDiv">gjpiy</div>
<div class="first"></div>
<div class="second"></div>
But my questions are different. Now here're my question:
If you change the
vertical-alignto the bigger div, all of the three blocks appear to move up..first, .second{ width: 100px; display: inline-block; } .first{ height: 100px; background: red; vertical-align:top; } .second{ height: 30px; background: yellow; }<div style="display: inline-block">gjpiy</div> <div class="first"></div> <div class="second"></div>If you change the
vertical-alignof the second div (the smaller one) only that goes up.
.first, .second{
width: 100px;
display: inline-block;
}
.first{
height: 100px;
background: red;
}
.second{
height: 30px;
background: yellow;
vertical-align:top;
}
<div style="display:inline-block">gjpiy</div>
<div class="first"></div>
<div class="second"></div>
So this is what I mean by the bigger element seems to influence Can anyone please clarify?
This is not really an "answer" per se but does illustrate where you see spans with
inline-blockwith and without content text (forced as ) also come into play here. The first three all have content; the last two the same layout as 2/3 but no content text.As does the specification reference from my comment here: (scroll down to the bottom of the section.) https://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-align
MDN flow discusssion reference https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_flow_layout/Block_and_inline_layout_in_normal_flow Includes some links to the BLOCK and INLINE BLOCK also at the bottom.