Came across a weird CSS issue. Can someone explain why the box having content is not vertically aligned?
If you put text inside the span with class .divPutTextToFixIssue
- it aligns properly.
<div id="divBottomHeader">
<div class="divAccountPicker">
<span class="divPutTextToFixIssue"><span>
</div>
<div class="divAccountData">
<span>Balance: $555</span>
</div>
</div>
#divBottomHeader {
background-color: #d5dbe0;
height: 43px;
}
.divAccountPicker {
display: inline-block;
background: blue;
width: 200px;
height: 40px;
}
.divAccountData {
display: inline-block;
background: red;
width: 400px;
height: 40px;
}
............................... Hi now add
vertical-align:top
in your.divAccountData, .divAccountPicker
class as like thisLIve demo
if you used to
display:inline-block;
than used to all-waysvertical-align:top
The default
vertical-align
value isbaseline
whichNote: You can see this default value in action by adding
vertical-align:baseline
to your.divAccountData
selector. Sincebaseline
is default the alignment is unchanged.You need to change it to
top
to align the blocks at the top, for example:Baseline is defined as
To address why adding text seems to fix the problem it is because
from CSS2 Visual formatting model details
So adding just a single character changes the baseline, causing the second block to appear at the same vertical alignment. This only works if both blocks contain the same number of lines. Try adding more words to one of your blocks and you will see that without forcing
vertical-align:top
on the second block it will move depending on how many lines of text exist in the first block.Edit: Found a related question Why is this inline-block element pushed downward?
try this
jsFiddle
You need to add
vertical-align: top;
to.divAccountPicker
demo