为什么来自Fontello的字体图标会呈现为空白框?

3

问题

我在应用了来自fontello.com的字体图标后,在网页上,<a>标签呈现如下,虽然它应该是这个左/右箭头:

enter image description here

背景

我使用这篇回答中的前四点作为使用fontello.com字体的教程。我不完全理解第五点(<i>标记部分),但它也是可选的。

........

我需要一个独立 (即不带文本) 的glyph图标放在<a>元素上,所以我做了这个:

<a href="" class="left-arrow icon-angle-left"></a>

and

<a href="" class="right-arrow icon-angle-right"></a>

在这个 <a> 元素的 CSS 中:

.right-arrow, .left-arrow {
    font-family: 'arrows';
    ...
}

这是从fontello.com下载的CSS文件夹中的arrows.css文件:

@font-face {
  font-family: 'arrows';
  src: url('../font/arrows.eot?42097229');
  src: url('../font/arrows.eot?42097229#iefix') format('embedded-opentype'),
       url('../font/arrows.woff?42097229') format('woff'),
       url('../font/arrows.ttf?42097229') format('truetype'),
       url('../font/arrows.svg?42097229#arrows') format('svg');
  font-weight: normal;
  font-style: normal;
}
/* Chrome hack: SVG is rendered more smooth in Windozze. 100% magic, uncomment if you need it. */
/* Note, that will break hinting! In other OS-es font will be not as sharp as it could be */
/*
@media screen and (-webkit-min-device-pixel-ratio:0) {
  @font-face {
    font-family: 'arrows';
    src: url('../font/arrows.svg?42097229#arrows') format('svg');
  }
}
*/

 [class^="icon-"]:before, [class*=" icon-"]:before {
  font-family: "arrows";
  font-style: normal;
  font-weight: normal;
  speak: none;

  display: inline-block;
  text-decoration: inherit;
  width: 1em;
  margin-right: .2em;
  text-align: center;
  /* opacity: .8; */

  /* For safety - reset parent styles, that can break glyph codes*/
  font-variant: normal;
  text-transform: none;

  /* fix buttons height, for twitter bootstrap */
  line-height: 1em;

  /* Animation center compensation - margins should be symmetric */
  /* remove if not needed */
  margin-left: .2em;

  /* you can be more comfortable with increased icons size */
  /* font-size: 120%; */

  /* Font smoothing. That was taken from TWBS */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* Uncomment for 3D effect */
  /* text-shadow: 1px 1px 1px rgba(127, 127, 127, 0.3); */
}

.icon-angle-right:before { content: '\e800'; } /* '' */
.icon-angle-left:before { content: '\e801'; } /* '' */

编辑 @Pauli_D

是的,我把它们放在那里了。我创建了一个小演示项目(我不知道如何在JSFiddle中添加fontello,所以在这里发布代码):

index.php:

<?php  

echo '<!DOCTYPE html>
<html>
    <head>      
        <meta charset="utf-8"/>
        <title>Test for Glyph Icon from Fontello</title>
        <link rel="stylesheet" type="text/css" href="style.css"/>
        <link rel="stylesheet" type="text/css" href="arrows.css"/>
    </head>
    <body>';

        echo '<a href="" class="right-arrow icon-angle-right"></a>';

        echo '<br><br><br>';

        echo '<a href="" class="left-arrow icon-angle-left"></a>';

    echo '</body>
    </html>';

?>

style.css:

.right-arrow, .left-arrow {
    font-family: 'arrows';
    color: #313131;
    text-align: center;
    text-decoration: none;
    width: 40px;
    font-size: 40px;
    padding-bottom: 60px;
    padding-top: 20px;
    filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=60);
    opacity: 0.6;
    -webkit-transition: opacity 0.3s ease;
    -moz-transition: opacity 0.3s ease;
    -o-transition: opacity 0.3s ease;
    transition: opacity 0.3s ease;
}

arrows.css与上述内容相同

..............

在此输入图片描述


1
你确实在文件夹中安装了这个字体吗?你能演示一下吗?它是在特定的浏览器中还是所有浏览器中都有问题? - Paulie_D
@Paulie_D 我编辑了问题。通过“安装在文件夹中”,我理解你是指字体文件(从fontello下载的包中的fonts文件夹中的.eot、.svg、.ttf、.woff文件)_位于_那里。是的,它们就在那里。 - Solace
那我建议你必须在实际页面上演示一下这个问题无法解决。 - Paulie_D
@Paulie_D 感谢您的建议,您能告诉我“live”网页是指在SO中插入的代码片段吗?我不知道如何将Fontello字体添加到其中。 - Solace
不,你必须创建一个实际的网站并将其托管在某个地方,以便我们可以看到这个问题无法工作。目前我们无法重现此问题,因此我们只能猜测。这很可能会导致问题被关闭。 - Paulie_D
首先,在浏览器开发工具中验证字体文件是否实际加载。其次,您的类是否有指定“content”属性的其他CSS?.icon-angle-left.icon-angle-right CSS是什么? - CodingWithSpike
2个回答

1

尝试

<a href=""><i class="left-arrow icon-angle-left"></i></a>
<a href=""><i class="right-arrow icon-angle-right"></i></a>

第五步仅涉及将零边距应用于您的图标。

编辑:

保留您现有的<a>元素,无需进行编辑。

在 arrows.css 文件中编辑路径并从路径开头删除 ../

@font-face {
font-family: 'arrows';
src: url('font/arrows.eot?42097229');
src: url('font/arrows.eot?42097229#iefix') format('embedded-opentype'),
     url('font/arrows.woff?42097229') format('woff'),
     url('font/arrows.ttf?42097229') format('truetype'),
     url('font/arrows.svg?42097229#arrows') format('svg');
font-weight: normal;
font-style: normal;
}

没有帮助。您可以在问题中看到编辑,以查看完整的演示项目。 - Solace
尝试从 .right-arrow, .left-arrow {} 的 CSS 中删除 font-family: 'arrows';。该字体系列是通过其 icon-* 类向元素分配的。 - mirek
当我尝试使用Font Awesome时,它对我有效-请参见[jsfiddle](http://jsfiddle.net/xq9s4Lpb/)。 - mirek
关于Fontello的问题。 - Solace
让我们在聊天中继续这个讨论 - Solace
显示剩余2条评论

0
因为你正在使用免费的“演示”字体,所以必须将“demo-icon”类添加到每个添加图标的类中。 例如:

目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接