首页 > 解决方案 > 如何在 Css 中为文本设置字体?

问题描述

有没有办法为css中的文本设置像“ Intro Black Regular ”这样的字体?!IDE 将“黑色”检测为一种颜色,而不是字体名称的一部分。

标签: javascripthtmlcss

解决方案


您需要按照 3 个步骤使用字体作为文本

  1. 设置@font-face

  2. 设置font-family名称

  3. font-family在 css 中使用

<!DOCTYPE html>
<html>
<head>
<style> 
@font-face {
  font-family: myFirstFont;
  src: url(sansation_light.woff);
}

div {
  font-family: myFirstFont;
}
</style>
</head>
<body>

<h1>The @font-face Rule</h1>

<div>With CSS, websites can finally use fonts other than the pre selected "web-safe" fonts.</div>

<p><b>Note:</b> Internet Explorer 8 and earlier, do not support the WOFF format (only supports EOT format).</p>

</body>
</html>


推荐阅读