首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未加载自定义图标字体

未加载自定义图标字体
EN

Stack Overflow用户
提问于 2014-10-18 18:26:03
回答 3查看 2.4K关注 0票数 0

我正在尝试将资料设计svg编译成一个字体.这是我的Gulpfile.js的一部分:

代码语言:javascript
复制
gulp.task('iconfont', function(){
  gulp.src(paths.svg)
    .pipe(iconfontCss({
      fontName: 'material-design', // required
      path: './www/sass/templates/_icons.scss',
      targetPath: '../sass/_icons.scss',
      fontPath: '/fonts/'
    })).pipe(iconfont({
      fontName: 'material-design', // required
    }))
    .pipe(gulp.dest('./www/fonts/'));
});

现在我的模板:

代码语言:javascript
复制
@font-face {
    font-family: "<%= fontName %>";
    src: url('<%= fontPath %><%= fontName %>.eot');
    src: url('<%= fontPath %><%= fontName %>.eot?#iefix') format('eot'),
        url('<%= fontPath %><%= fontName %>.woff') format('woff'),
        url('<%= fontPath %><%= fontName %>.ttf') format('truetype'),
        url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg');
}

.icon:before {
    font-family: "<%= fontName %>";
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
    // speak: none; // only necessary if not using the private unicode range (firstGlyph option)
    text-decoration: none;
    text-transform: none;
}

<% _.each(glyphs, function(glyph) { %>
<% var array = glyph.fileName.split('_') %>
.icon-<%= array.slice(1, array.length - 1).join('-') %>:before {
    content: "\<%= glyph.codePoint %>";
}
<% }); %>

问题:当我创建这样的元素时,我的图标没有加载

代码语言:javascript
复制
 <i class="icon-send"></i>

我什么也没看到。而且字体从未下载到服务器上(在网络日志中)。另外,图标是用不同的值定义两次的。摘录:

代码语言:javascript
复制
@font-face {
  font-family: "material-design";
  src: url('/fonts/material-design.eot');
  src: url('/fonts/material-design.eot?#iefix') format('eot'), url('/fonts/material-design.woff') format('woff'), url('/fonts/material-design.ttf') format('truetype'), url('/fonts/material-design.svg#material-design') format('svg'); }

.icon:before {
  font-family: "material-design";
  ...
  text-transform: none; }

.icon-3d-rotation:before {
  content: "\E001"; }

.icon-3d-rotation:before {
  content: "\E002"; }

.icon-accessibility:before {
  content: "\E003"; }

.icon-accessibility:before {
  content: "\E004"; }
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-10-19 02:48:13

可能是因为字体没有设置吗?字体系列是在“图标”类中定义的,但您没有指定它。如果您使用以下选项,会发生什么情况?

代码语言:javascript
复制
<i class="icon icon-send"></i>
票数 2
EN

Stack Overflow用户

发布于 2014-10-19 10:00:28

而不是使用两个类让您的图标工作,您可以更改您的字体系列添加到所有以icon-开头的CSS类中。

那么你只需要做这样的事情:

代码语言:javascript
复制
<i class="icon-send"></i>

下面是要做的改变:

代码语言:javascript
复制
[class^="icon-"]:before, [class*=" icon-"]:before {
  font-family: "material-design";
}
票数 1
EN

Stack Overflow用户

发布于 2014-10-18 20:29:29

我忘了应用icon ._类。

代码语言:javascript
复制
 <i class="icon icon-reply"></i>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26443105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档