I am stuck on this seemingly simple CSS problem. There are two divs, both have the same height and same font size, but different fonts. My goal is simply to verticall align the baseline and the borders of both divs.
Here is the first attempt:
.container {
display: flex;
align-items: center;
}
.d1, .d2 {
height: 1.4em;
line-height: 1.4em;
border: 1px solid blue;
font-size: 14px;
}
.d1 {
font-family: Roboto, sans-serif;
}
.d2 {
font-family: Roboto Mono, sans-serif;
}
<div class="container">
<div class="d1">0</div>
<div class="d2">0</div>
</div>
If we take a close look, the baseline is off by one pixel:
Now the same snippet with align-items: baseline;
.container {
display: flex;
align-items: baseline;
}
.d1, .d2 {
height: 1.4em;
line-height: 1.4em;
border: 1px solid blue;
font-size: 14px;
}
.d1 {
font-family: Roboto, sans-serif;
}
.d2 {
font-family: Roboto Mono, sans-serif;
}
<div class="container">
<div class="d1">0</div>
<div class="d2">0</div>
</div>
Now the basline is aligned, but the borders do not match anymore:
Is there a simple way to align the text of both divs while keeping the borders aligned?

