Custom icon font not loaded

落爺英雄遲暮 提交于 2019-12-12 01:58:37

问题


Using gulp-iconfont-css, I'm trying to compile Material Design svg into a font. This is the part of my Gulpfile.js:

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/'));
});

And now my template:

@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 %>";
}
<% }); %>

Problem: My icons are not loaded When I create an element like this:

 <i class="icon-send"></i>

I see nothing. And the font is never downloaded on the server (in the network log). Also, the icons are defined two times with different values. Extract:

@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"; }

回答1:


Is it perhaps because the font is not set? The font-family is defined in the "icon" class, but you are not specifying that. What happens if you use the following instead?

<i class="icon icon-send"></i>



回答2:


Instead of using two classes to have your icon working, you could change your font-family to be added on all the CSS classes that begin with icon-.

Then you will only have to do something like this:

<i class="icon-send"></i>

Here is the change to make:

[class^="icon-"]:before, [class*=" icon-"]:before {
  font-family: "material-design";
}



回答3:


I forgot to apply the class icon ._.

 <i class="icon icon-reply"></i>


来源:https://stackoverflow.com/questions/26443105/custom-icon-font-not-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!