Why are my descenders being cut off when using CSS

2019-01-23 03:59发布

I'm using the Google webfonts API to embed Droid Sans on a page. All is fine, except for the descenders (i.e. the dangly bits on y, g, etc). The latest versions of Firefox, IE and Chrome on my Windows Vista box are all cutting the bottom off.

<!DOCTYPE html>
<html>
<head>
 <title>Droid sans descender test</title>
 <meta charset="utf-8">
 <link href="http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold" rel="stylesheet" type="text/css">
 <style type="text/css">
  body { font-size: 16px; font-family: "Droid Sans", sans-serif; }
  h1, h2, h3 { margin: 1em 0; font-weight: normal; }
  h1 { font-size: 2em; }
  h2 { font-size: 1.5em; }
  h3 { font-size: 1em; }
 </style>
</head>    
<body>
 <h1>A bug ran under the carpet anyway</h1>
 <h2>A bug ran under the carpet anyway</h2>
 <h3>A bug ran under the carpet anyway</h3>
</body>
</html>

The above code looks like this:

Descenders getting cut off http://thinkdrastic.net/journal/wp-content/uploads/2010/06/descenders.png

I've tried line-height, font-size, padding etc to no avail. I had some success with font-size-adjust, but the last time I checked it was Gecko only. Does anybody know of a fix for this?

标签: css font-face
8条回答
家丑人穷心不美
2楼-- · 2019-01-23 04:44

Although your question is in relation to the Google Web Fonts API, the principle of my answer beneath is the same.

If the descendants are being cut-off when serving a TrueType Font, the most likely cause is that OS/2 metrics are incorrectly set (negatively) on the font.

The values that may need adjustment are WinAscent & WinDescent.

A quick and dirty fix would be to adjust these both to 0.

This can be done using Font Forge. Once the font is opened in FontForge, you can gain access to these parameters via the 'Font Info' dialogue.

查看更多
太酷不给撩
3楼-- · 2019-01-23 04:48

If the tip at the top - changing font-size to....

h1 { font-size: 1.6875em; }
h2 { font-size: 1.375em; }
h3 { font-size: 1.125em; }

doesn't work for you, then add "line-height" to the element that is cutting off the descenders. ``

查看更多
登录 后发表回答