如何在 CodePen 上使用字体 ttf



我是CSS世界的新手,我正在练习 codepen.io

我想在我的笔中添加某种字体。我从网站上下载了它,然后尝试将其上传到 github 并使用该文件的链接,但它在>不起作用,<</p>

您可以在此处找到代码:http://codepen.io/Koop4/pen/mVaOLG

或阅读以下内容:

<body>
  <h1>Hello World</h1>
</div>
</body>
html,
body {
  height: 100%;
  background-image: linear-gradient(to bottom, #0B88FF, #95EEFF);
}
@font-face {
  font-family: 'superMario';
  src: url('https://github.com/koop4/FreeCodeCamp/blob/master/portfolio/font/prstart.ttf');
}
h1,
h2,
h3 {
  font-family: 'superMario'
}

提前感谢!

因为.ttf文件的URL是页面而不是文件路径。您必须使用字体文件的直接链接。使用这个:

@font-face {
  font-family: 'superMario';
  src: url('https://raw.githubusercontent.com/koop4/FreeCodeCamp/master/portfolio/font/prstart.ttf');
}

如果不起作用,则必须在其他主机中上传字体文件,然后使用它。

最新更新