I would like to fully understand what happens when there are conflicts in baseline positioning and there are different vertical-align
in adjacent inline elements. I’ve tried testing this on more complex scenarios but in a nutshell the baseline moves up or down based on what element comes first, and I can’t find an answer in the documentation to how these conflicts are resolved.
.container {
color: white;
background-color: black;
width: 160px;
border: 4px solid black;
}
.foo,
.bar {
display: inline-block;
width: 60px;
height: 60px;
}
.foo {
background-color: orange;
vertical-align: top;
}
.bar {
background-color: yellowgreen;
vertical-align: bottom;
}
<div class="container">
A
<!-- swap foo with bar -->
<div class="foo">
B
</div>
<div class="bar">
C
</div>
</div>
2
Answers
Note this has to do with the
display: inline-block;
lots of details here:https://stackoverflow.com/a/35531553/125981 but you can just change totable-cell
also.Actually there is no clear answer. From the Specification:
As you can read, we can have multiple solutions thus multiple baseline and the specification doesn’t define which one to use.
It’s the case of your example and if you test your code on different browsers you won’t get the same baseline.
Chrome choose top
Firefox choose bottom