Home  >  Article  >  Web Front-end  >  How to set the font in css to Microsoft Yahei

How to set the font in css to Microsoft Yahei

青灯夜游
青灯夜游Original
2021-03-31 17:17:2223736browse

In CSS, you can use the font-family attribute to specify the font of an element. You only need to add "font-family:"Microsoft YaHei";" or "font-family:"Microsoft YaHei" to the element. ;" style can set the element font to Microsoft Yahei.

How to set the font in css to Microsoft Yahei

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

In CSS, you can use the font-family attribute to set the font to Microsoft Yahei. Syntax:

font-family:"微软雅黑";

But you need to pay attention to one thing. Usually when we use Chinese fonts, we will use English name instead of using Chinese directly. Therefore, it can also be set like this:

font-family:"Microsoft YaHei";

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style>
p{
font-family:"Microsoft YaHei",微软雅黑;

}
</style>
</head>

<body>
<p>这是微软雅黑字体</p>
</body>
</html>

Rendering:

How to set the font in css to Microsoft Yahei

Recommended tutorial: CSS video tutorial

css font-family attribute description:

font-family specifies the font family of the element.

font-family can save multiple font names as a "fallback" system. If the browser doesn't support the first font, it will try the next one. That is, the value of the font-family attribute is a precedence list of font family names or/and class family names to use for an element. The browser will use the first value it recognizes.

There are two types of font family names:

  • Specified series name: the name of the specific font, such as: "times", "courier", "arial" .

  • Usual font family names: For example: "serif", "sans-serif", "cursive", "fantasy", "monospace"

Tip: Separate each value with a comma, and always provide a family name as a last resort.

Note: The use of a specific font family (Geneva) depends entirely on whether the font family is available on the user's machine; this attribute does not indicate any font download. Therefore, it is highly recommended to use a common font family name as a fallback.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of How to set the font in css to Microsoft Yahei. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn