html - 在 CSS 中使用图标字体时遇到问题

标签 html css icon-fonts

我是网页设计和开发的新手,一直在研究不同的样式技术。在我的研究过程中,我遇到了图标字体。尽管我已经研究了许多教程和视频,但尽管经过了数小时的努力,我仍无法成功使用图标字体。

首先,我去了一个提供大量图标字体的网站,选择我喜欢的,生成它们,最后将它们下载到一个文件夹中。但是现在这些图标字体都在一个文件夹里了,怎么办呢?

最佳答案

这是一步一步的指南:

转到 Font Squirrel并下载 @font-face 套件。解压缩,将其重命名为“fonts”,并将其放在与 html 文件相同的目录中。

将其用作您的 html 文件:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <style>
    @font-face {
    font-family: 'ModernPictogramsNormal';
    src: url('fonts/modernpics-webfont.eot');
    src: url('fonts/modernpics-webfont.eot?#iefix') format('embedded-opentype'),
         url('fonts/modernpics-webfont.woff') format('woff'),
         url('fonts/modernpics-webfont.ttf') format('truetype'),
         url('fonts/modernpics-webfont.svg#ModernPictogramsNormal') format('svg');
    font-weight: normal;
    font-style: normal;
    }
    li {
      list-style-type: none;
    }
    [data-icon]:before {
      font-family: 'ModernPictogramsNormal';
      content: attr(data-icon);
      speak: none;
      padding:0 5px;
    }
    </style>
</head>
<body>
  <ul>
    <li data-icon="^">RSS</li>
    <li data-icon="*">Star</li>
    <li data-icon=".">Shopping Cart</li>
  </ul>
</body>
</html>

你应该看到这个:

Icon Font Example

你在滚动!

此外,要了解要使用的字符,请查看 Font Squirrel 网站上的字符映射表。

关于html - 在 CSS 中使用图标字体时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13129995/

相关文章:

javascript - 用于将日期输入表单的 HTML 选择和日历的用例

html - Bootstrap 不显示我的表单的背景颜色

html - 如何制作具有网页高度的 slider ?

javascript - 是否有可能在*不*捆绑浏览器的情况下构建独立的 HTML5 应用程序?

javascript - 将 d3 Legend 放入单独的 Div

java - Xpath - 如何获取元素之间包含的数据,而不是元素本身

css - 嵌套媒体查询

css - 为什么 Opera 显示 Google 的 Material Symbols Outlined(图标字体)不正确,如何修复?

css - 大 Iconfont 图标在右侧被切断

sencha-touch-2 - Sencha Architect 3 不使用 app.css