【问题标题】:Adding multiple Icomoon fonts to the website向网站添加多种 Icomoon 字体
【发布时间】:2015-12-06 21:31:36
【问题描述】:

我聘请开发移动网站的开发公司未能将 selection.json 文件包含到文件夹中,甚至从未想过将其保存在本地以供自己在支持期间参考...基本上,他们确实包含是字体文件:TTF、EOT、SVG 和 WOFF。

以下是 Icomoon 关于向现有字体添加更多字形的说明:您从 IcoMoon 应用下载的每个字体包都附带一个 selection.json 文件,您可以将其导入回应用以修改或更新您的字体,以及与其字形相关的类名。

现在我需要为字体添加更多字形。看起来最简单的方法是生成另一种字体,并将其添加到 style.css。你能告诉我怎么做吗?原来的行是:

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

[class^="icon-"],    
[class*=" icon-"] {    
  speak: none;    
  line-height: 1;    
  font-style: normal;    
  font-weight: normal;    
  font-variant: normal;    
  text-transform: none;    
  font-family: 'icomoon';}

  /* Better Font Rendering =========== */

或者,也许还有另一种方法可以在此字体中添加图标,而不会破坏其结构并且不必修改整个 CSS 来更改整个网站的类名?

谢谢!

【问题讨论】:

  • 你应该解释一下“section.json”,不熟悉icomoon的人都看不懂。
  • 编辑您的问题以包含 icomoon 所说的内容,而不仅仅是将其发布为评论。人们会阅读您的问题,直到他们迷失在 selection.json 部分,然后投票关闭问题而不阅读所有 cmets。
  • 好的,谢谢你的提示。我是新手。
  • 不客气。这就是评论者的目的:)

标签: css svg fonts icons webfonts


【解决方案1】:

一种选择是查找当前图标字体中的所有图标,并使用当前图标以及您想要包含的任何新图标创建新字体。然后,您将用新字体替换当前字体。

另一种选择是创建仅包含新图标的新字体,然后将其与现有图标​​字体一起包含在您的网站中。使用 icomoon 应用程序,您可以通过单击“首选项”来自定义字体名称和类前缀。我建议这样做以避免与您网站中包含的当前“icomoon”字体发生冲突。

如果您想同时包含旧字体和新字体,那么您将包含一些与此类似的 CSS(由 icomoon 生成):

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

@font-face {    
  font-family: 'ourotherfontname';    
  src: url('../fonts/icomoon/ourotherfontname.eot?t9csor');    
  src: url('../fonts/icomoon/ourotherfontname.eot?#iefixt9csor') format('embedded-opentype'), url('../fonts/icomoon/ourotherfontname.woff?t9csor') format('woff'), url('../fonts/icomoon/ourotherfontname.ttf?t9csor') format('truetype'), url('../fonts/icomoon/ourotherfontname.svg?t9csor#ourotherfontname') format('svg');    
  font-weight: normal;    
  font-style: normal;
}

[class^="icon-"],    
[class*=" icon-"],
[class^="anoterclassprefix-"],    
[class*="anotherclassprefix-"] {    
  speak: none;    
  line-height: 1;    
  font-style: normal;    
  font-weight: normal;    
  font-variant: normal;    
  text-transform: none;    
  font-family: 'ourotherfontname';}

  /* Better Font Rendering =========== */

【讨论】:

  • 谢谢史蒂夫。第一个选项的问题是他们使用了自定义图标,在 icomoon 上找不到。关于第二个,是的,我知道 icomoon 提供了一个示例 css,我的问题是如何使用这两种字体,我如何将它们都放在 CSS 中?
  • @Andy 我相信您应该能够使用 .svg 字体文件将图标重新导入 icomoon。
  • 我是,但如果没有 selection.json 文件,所有数据,即类名、字形结构等都会丢失。如果我用新图标扩展它,并生成新字体,我将不得不修改整个网站以确保新类到位,作为一个 CSS 新手,这是一项艰巨的工作......跨度>
  • @Andy 说得通。你最好的选择可能是创建一个额外的字体并包含它。
  • 这就是我想要弄清楚的......据我所知,字体规则需要出现在 style.css 文件的顶部。如果我使用两个,我该如何放置它们?首先是规则,然后是类,我的意思是这些东西:'[class^="anoterclassprefix-"], [class*="anotherclassprefix-"] { speak: none;行高:1;字体样式:正常;字体粗细:正常;字体变体:正常;文本转换:无; font-family: 'ourotherfontname';}' 还是两个规则一个接一个的附加数据?
猜你喜欢
  • 1970-01-01
  • 2015-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-09
  • 1970-01-01
相关资源
最近更新 更多