【问题标题】:Kerning on font between chrome and firefoxchrome和firefox之间的字体字距调整
【发布时间】:2012-10-06 19:55:12
【问题描述】:

我正在制作一个带有自定义字体的菜单,并且在 chrome(和 safari)中,它的间距完全符合我的要求。

http://american-motorsports.net/2012/

当我在 Firefox 中查看时,字体的字距有点不同,导致最右边的菜单项上有一点黑色间隙。我可以看到 FABRICATION

FA 之间的区别

现在的 HTML 非常简单:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="resources/css/reset.css" />
<link rel="stylesheet" href="resources/css/main.css" />
<title><?php echo date('M d, Y') . ' | '; ?>American Motorsports - Off-Road Fabrication</title>
</head>
<body>
<div id="wrap">
    <div id="header">
        <div id="logo">
            <img src="resources/images/logo.png" width="291" height="150" alt="American Motorsports - Off-Road Fabrication" />
        </div>
        <div id="menu">
            <a href="#"><span class="item">HOME</span></a><a href="#"><span class="item">SUSPENSION</span></a><a href="#"><span class="item">FABRICATION</span></a><a href="#"><span class="item">PROJECTS</span></a><a href="#"><span class="item">MEDIA</span></a><a href="#"><span class="item">CONTACT</span></a>
        </div>
    </div>
    <div id="main"></div>
</div>
</body>
</html>

到目前为止,CSS 由这些组成

@font-face {  
    font-family: bebas;  
    src: url("../fonts/bebas.ttf") format("truetype");  
    font-weight: normal;
    font-style: normal;
}

body {
    font-size: 14px;
    color: #ccc;
    line-height: 20px;
    margin: 0;
    padding: 0;
    background: url("../images/bg.png") #202020;
}

#wrap {
    background: url("../images/bg_main.jpg") no-repeat center top;
    min-height:800px;
}

#header {
    border-top: 5px solid #3a3a3a;
    height:150px;
    width:970px;
    background-color:#000000;
    margin: 50px auto;
}

#logo {
    width:324px;
    height:179px;
    background-color:#121212;
    border-top: 5px solid #3a3a3a;
    border-bottom: 5px solid #ffffff;
    margin-top:-22px;
    float:left;
}

#logo img {
    margin-left:13px;
    margin-top:17px;
}

#menu {
    width:646px;
    height:150px;
    float:right;
    margin:0;
    padding:0;  
}

#menu a {
    margin:0;
    padding:0;
}

.item {
    font-family:bebas;
    font-size:18px;
    height:150px;
    display:inline-block;
    text-align:center;
    line-height:8em;
    color:#fff;
    cursor:pointer;
    padding-left:20px;
    padding-right:20px;
    margin:0;
    text-shadow: 0 3px 3px #111;
}

.item:hover {
    background: -moz-linear-gradient(top,  #3a3a3a 0%, #101010 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#3a3a3a), color-stop(100%,#101010));
    background: -webkit-linear-gradient(top,  #3a3a3a 0%,#101010 100%);
    background: -o-linear-gradient(top,  #3a3a3a 0%,#101010 100%);
    background: -ms-linear-gradient(top,  #3a3a3a 0%,#101010 100%);
    background: linear-gradient(to bottom,  #3a3a3a 0%,#101010 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#3a3a3a', endColorstr='#101010',GradientType=0 );
}

#main {
    width:970px;
    /*background-color:#ffffff;*/
    margin: 0 auto;
}

所以问题是如何消除间隙,使其看起来像 chrome 和 safari 或修复字距调整问题..我只是不希望 Firefox 中的间隙

【问题讨论】:

  • 仅供参考,Safari 中仍然存在差距(至少在 iOS 设备上)。

标签: css firefox google-chrome kerning


【解决方案1】:

我看不出您要消除什么差距,但您所描述的是 Firefox(现代版本)默认应用字距调整(如果在字体中定义)的问题。其他浏览器没有。所以这是字距调整与无字距调整的问题,而不是字距调整的差异。字距调整通常被认为是印刷上可取的。但如果你真的想阻止 Firefox 进行字距调整,可以使用 font feature settings,例如在这种情况下与

#menu  { -moz-font-feature-settings: "kern" 0; }

【讨论】:

  • 我已经上传了修复程序,这就是您看不到它的原因。不过我现在也要试试这个
  • 嗯,似乎没有什么不同。我在菜单 div 以及作为菜单项的 item 类上进行了尝试
  • 我已将最新版本上传到我在我的 OP 中发布的链接。它现在可以工作了
  • @vsync,您的评论是关于您在混乱的环境中使用另一种字体。如果你有问题,你应该提出自己的问题,解释问题(“不起作用”不是描述),并将问题减少到最小的演示案例。
  • 这对我使用 Google Fonts 字体的 Firefox 32、Linux 没有任何影响。 IE。 Firefox 中的文本宽度没有改变,并且仍然与它在 Chrome 中的显示方式不同(Chrome 的间距更大)。很遗憾,因为这看起来就是解决方案!
【解决方案2】:

一个快速肮脏的解决方案是

#menu{
  white-space: nowrap;
  overflow: hidden; /* means you don't get a dirty edge, but the last link may be smaller on the right */
}

但理想情况下,您不应该依赖字体的宽度来使您的菜单看起来正确。 如果你有时间,给每个链接一个类和一个自定义宽度。 或者更好的是,在每个项目中使用带有链接的列表,以获得更好的控制。

例如,如果您添加:

.item{
  padding: 0;
  width: 16.66%; /* assuming you always have 6 links */
}

...它们总是合适的,但有些看起来很垃圾。 为了获得最专业的外观,您需要为每个对象指定一个类和自定义宽度。

【讨论】:

  • 是的,制作单独的课程肯定会奏效,如果可以的话,我想让它尽可能动态。我可能不得不这样做
  • 我最终为每个菜单项提供了自己的类并手动设置了宽度,现在它在所有浏览器中都是一致的.menuOne {width:80px} .menuTwo {width:130px} .menuThree {width:134px} .menuFour {width:112px} .menuFive {width:85px} .menuSix {width:105px}
【解决方案3】:

您必须将 span 包裹在有问题的字母周围,并调整 CSS letter-spacing: 属性,直到得到您想要的。

良好的排版技巧,尤其是在自定义字体方面,还没有为浏览器的黄金时段做好准备。

B 计划:使用图片。

【讨论】:

  • 是的,这是我第一次使用自定义字体。我曾想过使用图像,但如果我不必这样做,那就太棒了。我将尝试您对字母间距的建议。我会报告的,谢谢!
  • 我可以把它变大,但不能用字母间距变小,所以我走的是给每个菜单项一个类并定义宽度的路线
猜你喜欢
  • 2011-12-29
  • 1970-01-01
  • 1970-01-01
  • 2017-01-10
  • 2020-09-11
  • 2014-04-25
  • 2014-12-19
  • 2011-08-30
  • 1970-01-01
相关资源
最近更新 更多