Suppose I have a single line of text that is in all caps (e.g. with text-transform: uppercase
). I want to center this text vertically in a div
. I don't need to worry about multi-line text.
There are several ways to center things vertically in CSS (e.g. check this out). Unfortunately, all these methods take descenders into account, and my text doesn't have any descenders so it isn't centered perfectly. Basically, I want to center the portion of the text from the baseline to the cap height.
Is there any way to vertically center a line of capitalized text? Right now I'm using position: relative
and manually tweaking it until it is centered (e.g. with top: 2px
), but this is clearly not a robust solution (it is very dependent on the way the browser renders text, what fonts are available, etc.). Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…