html - CSS:文本随机显示为斜体,以及什么都没有改变
问题描述
所以我的问题是,我有一个关于列表的练习,我正在做,我从 Google Fonts 导出字体 Exo 2,如下所示:
@font-face {
font-family: 'Exo 2', sans-serif;
src: url('https://fonts.googleapis.com/css2?family=Exo+2:wght@300&display=swap');
}
但是当我将字体分配给类似的东西h1
并h2
添加时font-weight:500;
(因为否则默认h1
字体粗细对于我正在做的样式来说太重了),字体随机变成了italics。当我尝试使用 强制它恢复正常font-style: normal;
时,它仍然是那样。让它不是斜体的唯一方法是如果我保留默认重量。
为什么是这样?我该如何解决这个问题?
MRE:
HTML
@font-face {
font-family: 'Exo 2', sans-serif;
src: url('https://fonts.googleapis.com/css2?family=Exo+2:wght@300&display=swap');
}
*{
font-family: 'Exo 2', sans-serif;
}
h1,h2{
font-weight: 500;
font-style: normal;
}
<h1>Mugekenaga</h1>
<h2>Komeji</h2>
<ol>
<li>Fomikatarye</li>
<li>Domikatarye</li>
</ol>
解决方案
(<!DOCTYPE html>
如果没有,请在最顶部指定)
尝试以这种方式导入谷歌字体:
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Exo+2:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
css
*{font-family: 'Exo 2', sans-serif;}
h1,h2{font-size: 30px; font-weight: 300;}
html
<h2>Komeji</h2>
<ol>
<li>Fomikatarye</li>
<li>Domikatarye</li>
</ol>
只是一个旁注,取决于您使用的浏览器,有时对于 h1~h*,字体粗细的数值可能无法识别。
我已经在 chrome 上尝试过这段代码,似乎所有 100~900 的字体粗细都可以正常工作。为了您的方便,我将完整的代码放在下面。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Exo+2:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<style>
*{font-family: 'Exo 2', sans-serif;}
h1,h2{font-size: 30px; font-weight: 300;}
</style>
</head>
<body>
<h2>Komeji</h2>
<ol>
<li>Fomikatarye</li>
<li>Domikatarye</li>
</ol>
</body>
</html>
推荐阅读
- object - 如何在 Ocaml 的对象中使用另一个 val 定义一个 val?
- sas - 如何存储和传递我的 SAS 结果值?
- r - 停止错误(“动画”,类(绘图)[1],“不支持对象”):缺少参数“绘图”,没有默认值
- reactjs - 如何使用 React 将事件传递给 JavaScript 函数?
- r - 是否有 R 函数来解决“找到两个总和为 x 且乘积为最大值的数字”之类的问题?
- python - 如何在windows上通过python获取多个eternet mac地址?
- scala - Apache Bahir 库的 Scala 2.11 编译
- azure-data-factory - 连接到 MySQL 时如何使用 Azure 数据工厂 (ADF) 解决超时问题?
- c - 如何在 Linux 中调试无调试符号的 C 程序?
- c# - IComparer 未实现接口成员 - 错误 CS0738