Does WebKit have a clipping bug?

社会主义新天地 提交于 2019-12-03 10:52:37

It appears this has to do with descenders (qjpg) "sticking out" down below the line-height box. Firefox and Safari seem to agree on how to do this - characters are allowed to stick out. However by exaggerating the sizes x 10, we notice something interesting for sans-serif.

In Mac OS X, both Safari and Firefox chose helvetica as the typeface for sans-serif. But Firefox moves that particular typeface upwards in the line-height box, so the bottom doesn't "stick out". Compare with arial - microsoft's bastardization of helvetica where both browsers let it stick out.

I think the solution to your problem is to find a "reasonable" negative margin to offset the content upwards. It seems both helvetica and arial have some "wiggle room" at the top of the box. I would use #wrapper #content { margin-top: -1px; } (selector extra strong to overcome #wrapper *) for the specific font-size/line-height in your example.

Here's my test code. It shows that the "sticking out" can be much worse for geneva and verdana.

<!DOCTYPE HTML> 
<html lang="en"> 
    <head> 
        <meta charset="utf-8"/> 
        <title>descender issue</title> 
        <style> 

          * {
            margin: 0;
            padding: 0;
          }

          .content {
            margin-bottom: 30px;
            background: #ffdd88;
            font-size: 190px;
            line-height: 210px;
          }

          #content1 {
            font-family: sans-serif;
          }

          #content2 {
            font-family: arial;
          }

          #content3 {
            font-family: geneva;
          }


          #content4 {
            font-family: helvetica;
          }

          #content5 {
            font-family: 'trebuchet ms';
          }

          #content6 {
            font-family: verdana;
          }

          #content7 {
            font-family: serif;
          }

          #content8 {
            font-family: times;
          }

        </style> 
    </head> 
    <body> 
      <h1>descender issue</h1> 
      sans-serif
        <div class="content" id="content1"> 
          lfgjpq
        </div> 
      arial
        <div class="content" id="content2"> 
          lfgjpq
        </div> 
      geneva
        <div class="content" id="content3"> 
          lfgjpq
        </div> 
      helvetica
        <div class="content" id="content4"> 
          lfgjpq
        </div> 
      trebuchet ms
        <div class="content" id="content5"> 
          lfgjpq
        </div> 
      verdana
        <div class="content" id="content6"> 
          lfgjpq
        </div> 
      serif
        <div class="content" id="content7"> 
          lfgjpq
        </div> 
      times
        <div class="content" id="content8"> 
          lfgjpq
        </div> 
    </body> 
</html>

Have you tried increasing line height by 1px? I tried it in Chrome and it works:

line-height: 22px;
height: 220px; /* A multiple of line height */

and:

document.getElementById('wrapper').scrollTop += 220;

Alternatively you can reduce the font size by 1px which also works for me:

/* alternative solution: */
font-size: 18px;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!