首页 > 解决方案 > 网站未在本地使用导入的 Google 字体,但在 codepen 中工作

问题描述

我有一个测试站点,我正在制作它不使用导入的字体或备份字体。奇怪的是,虽然它不会在本地更改字体,但将代码放入 codepen 就可以了。

如果您想知道,我的所有文件都在正确的位置(见图)

文件结构

此外,这是我的源代码的codepen 链接,它也在下面:

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;700&display=swap');
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

html {
  font-family: 'Montserrat', sans-serif;
  font-size: 10px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Test Page</title>
  <meta name="description" content="Test Page" />
  <meta name="author" content="test Page" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <link href="style.css" ref="stylesheet">
</head>

<body>
  <section id="hero">
    <div class="hero container"></div>
    <div>
      <h1>Test Header</h1>
      <a href="javascript:void(0)" type="button" class="cta">Test Button</a>
  </section>

  <script src="main.js"></script>
</body>
<html>

标签: htmlcssfonts

解决方案


rel不是ref用于链接样式表

<link href="style.css" rel="stylesheet">

推荐阅读