My text is not vertically centered and my designers are pointing it out.
However, I am using the proper CSS to achieve vertical centering, that is not the issue.
The problem lies in the font itself. The glyphs are not centered in the actual text. Selecting the text reveals its bounding box, and from here I can see an uneven amount of space below the text.
Line-height does not appear to fix this issue. The bounding box is still off, even with a line-height of 0. I can add padding to the top of my elements to attempt to fix this problem, but that's not going to be scalable across the many elements that use this font.
It appears that the uneven space is because of descenders. This makes sense, but unfortunately it doesn't get me any closer to figuring out how to truly vertically center this text.
The font in question is SouvenirStd-Medium, but I have noticed this with many other web fonts. It is consistently off no matter which element is used... h1's, paragraph tags, etc.
Although it probably wont be useful, here is an example my styles for headlines:
font-family: SouvenirStd-Medium;
font-size: 5rem;
font-weight: 400;
font-style: normal;
line-height: 1.3;
letter-spacing: 0;
And an example of how I am centering my text in a wrapping tag.
div {
display: flex;
height:100px;
align-items: baseline;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…