Webfont + 悬停颜色:部分文本不改变颜色颜色、不改变、文本、部分

2023-09-08 10:03:05 作者:灭世小仙女

我见过几次,只是在 Webkit 上.场景是您有一些带有悬停颜色的文本,并且它使用 webfont 自定义字体.当您悬停时,最右边的部分字母没有获得悬停颜色.要明白我的意思,请在 Chrome 或 Safari 中查看此小提琴,并在鼠标悬停时仔细查看文本末尾的r",它不是完全红色的.

I've seen this a few times, only on Webkit. The scenario is that you have some text with a hover color, and it's using a webfont custom font. When you hover, part of the furthest right letter is not getting the hover color. To see what I mean, view this fiddle in Chrome or Safari, and look carefully at the "r" at the end of the text while hovering with your mouse, it is not completely red.

http://jsfiddle.net/jaredh159/xPZB8/

来自小提琴的 HTML:

HTML from fiddle:

<a>Some Text Foo Bar</a>

来自小提琴的 CSS:

CSS from fiddle:

@font-face {
    font-family: 'stephanie_marie_jfregular';
    src: url('stephanie-marie-jf-webfont.eot');
    src: url('stephanie-marie-jf-webfont.eot?#iefix') format('embedded-opentype'),
         url('stephanie-marie-jf-webfont.woff') format('woff'),
         url('stephanie-marie-jf-webfont.ttf') format('truetype'),
         url('stephanie-marie-jf-webfont.svg#stephanie_marie_jfregular') format('svg');
    font-weight: normal;
    font-style: normal;
}

a {
    font-family: stephanie_marie_jfregular;
    color: #000;
    font-size:50px;
}

a:hover {
    color: #ff0000;
}

这是什么?可修复?仅仅是创建不良的网络字体文件还是错误的字体?任何人都熟悉这个问题或有解决方法?

What is this? Fixable? Is it just the case of a poorly created web-font file, or a bad font? Any one familiar with this issue or have a workaround?

推荐答案

右边的几个像素没有给出它们的 :hover 颜色的原因是因为它们在 a容器.检查它或给它一个背景色,你可以看到这个.一种解决方法是通过给 a 一些额外的 padding-right 来伪造额外的空间.

The reason the right few pixels arent't given their :hover color is because they run outside the a container. Inspect it or give it a background color and you can see this. A workaround is faking the extra space by giving the a some extra padding-right.

我不确定字形究竟是如何在容器外运行的,所以如果其他人知道的话,我很感兴趣.现在我和 celeriko 一样怀疑这种字体的指标有问题.

I'm not sure how exactly the glyph is able to run outside the container, so I'm be interested if anyone else knows. For now I'm sharing celeriko's suspicion that this font's metrics are borked.

原来是字体的侧轴承 允许字形在其边界框之外运行.这在画笔字体中很常见,并且允许单个字母通过略微重叠来连接.所以它是字体的一个有效属性,不幸的是,它导致了一个原始印刷者不必考虑的问题——纸上没有悬停状态;)

Turns out it's the font's side bearings that allow for the glyph to run outside its bounding box. This is common with brush script fonts and allows individual letters to connect by slightly overlapping eachother. So it's a valid property of the font, unfortunately causing a problem the original typographers didn't have to account for — no hover states on paper ;)