【问题标题】:Why does this font-icon from fontello render like an empty box?为什么这个来自 fontello 的字体图标呈现为一个空框?
【发布时间】:2022-02-16 21:32:26
【问题描述】:

问题

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

背景

我使用the first four points from this answer 作为教程来使用来自fontello.com 的字体。我不完全理解第 5 点(<i> 标签部分),但它也是可选的。

........

我需要在 <a> 元素上使用独立(即不带文本)字形图标,所以我这样做了:

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

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

在这个 &lt;a&gt; 元素的 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 同上

.......

【问题讨论】:

  • 您确实在文件夹中实际安装了字体...不是吗?你能演示一下吗?是在任何特定浏览器中还是在所有浏览器中?
  • @Paulie_D 我编辑了这个问题。通过“安装在文件夹中”,我假设您的意思是字体文件(.eot.svg.ttf.woff 来自从 fontello 下载的包中的 fonts 文件夹中的文件)是 位于那里。是的,它们就在那里。
  • 那么我建议你必须在 live 页面上进行演示。
  • @Paulie_D 感谢您的建议,您能否告诉我,如果通过 live 网页,您是指在 SO 中插入的代码 sn-ps 吗?我不知道如何给它们添加 Fontello 字体。
  • 不,您必须创建一个实际的网站并将其托管在某个地方,这样我们才能看到这不起作用。目前我们无法重现该问题,因此我们进行了疯狂的猜测。这可能会解决问题。

标签: css webfonts glyphicons fontello


【解决方案1】:

试试

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

第 5 步仅指对图标应用零边距。


编辑:

保留您现在拥有的 &lt;a&gt; 元素,无需编辑。

编辑 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;
}

【讨论】:

  • 没有帮助。您也可以在问题中查看编辑,以查看完整的演示项目。
  • 尝试从 .right-arrow, .left-arrow {} 的 CSS 中删除 font-family: 'arrows';。 font-family 由其 icon-* 类分配给元素
  • 当我尝试使用 Font Awesome 时为我工作 - 请参阅 jsfiddle
  • 您对尝试的建议!无意冒犯,但你是在随机猜测吗?如果没有,请在您建议某人尝试某事时说明原因。
  • 关于Fontello的问题。
【解决方案2】:

因为您使用的是免费的“演示”字体,因此必须将“演示图标”类添加到您添加每个图标的每个类中。 示例:

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-20
  • 2012-12-22
相关资源
最近更新 更多