简体   繁体   English

CSS上下字体间距不一致

[英]css inconsitent spacing above and below font

I am using two different fonts in my website - "sans-serif" and "tradeGothicLTStd". 我在网站上使用了两种不同的字体:“ sans-serif”和“ tradeGothicLTStd”。 Here is how these fonts are rendered in the browser. 这些是在浏览器中呈现这些字体的方式。

无衬线字体

贸易哥特式-LT-STD

You can notice that in the first screenshot there is some extra space above the font (If you see the uppercase text. Please open it in a new tab with black background to properly see the difference) and while using another font there is no extra space above the font (uppercase text). 您可能会注意到,在第一个屏幕截图中,字体上方有一些多余的空间(如果看到大写的文本。请在带有黑色背景的新标签页中打开它以正确看到区别),而使用其他字体时则没有多余的空间字体(大写文本)上方。

Here is how they are rendered when used in a button. 这是在按钮中使用它们时的呈现方式。

无衬线字体

贸易哥特式-LT-STD

Because of these inconsistencies the fonts go out of position vertically. 由于这些不一致,字体在垂直方向上不正确。 ie if I design my css with first font in mind the all uppercase fonts are centered vertically (inside a button or anchor tag etc) but when I change the font to the second font all text kind of moves little upwards since there is no extra space above the font in this case. 例如,如果我在设计CSS时考虑到第一种字体,则所有大写字体都垂直居中(在按钮或锚标记等内部),但是当我将字体更改为第二种字体时,所有文本都会稍微向上移动,因为没有多余的空间在这种情况下,字体上方。 Because of this my font is not perfectly vertically aligned in the center. 因此,我的字体未在中心垂直完美对齐。

Is there any way to fix this or can someone even tell me why this is happening? 有什么办法可以解决此问题,或者有人可以告诉我为什么会这样?

On your second picture the font also appears to be stretched. 在第二张图片上,字体也似乎被拉伸了。 You can scale the font with transform: scale(1, 0.9); 您可以使用transform: scale(1, 0.9);缩放字体transform: scale(1, 0.9); . This will scale the font vertically on 90%. 这会将字体垂直缩放90%。

Then, I would use line-height 然后,我将使用line-height

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM