Home >Web Front-end >Front-end Q&A >How to set the font set by css
The font set by CSS can be set in the following ways:
You can directly specify the font you want to use in the CSS style sheet The name of the font. For example, if you want to use Arial font, you can add the following code to your stylesheet:
body { font-family: Arial, sans-serif; }
This will make all text in your website use Arial font. sans-serif
is a generic font family name used to refer to sans-serif fonts, used as a backup font when the browser cannot display the specified font.
Web fonts are provided by your server, so you can use any custom fonts. To use web fonts, you need to add the following code to your CSS stylesheet:
@font-face { font-family: "MyFont"; src: url("myfont.woff"), local("MyFont"), url("myfont.ttf"); }
In this example, MyFont
is the name of this custom font, myfont.woff
and myfont.ttf
are the paths to the font files. This code block defines a rule named @font-face
, and then specifies the name of the font and the path to the font file in the rule.
Google provides a free web font service for use in your website. To use Google Fonts, you need to add the following code to your CSS stylesheet:
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
In this example, Open Sans
is the name of the font to use. You can then use this font in your stylesheet just like you would any other font:
body { font-family: "Open Sans", sans-serif; }
This will make all text in your site use Google-provided Open Sans
Font.
In general, you can set CSS fonts by specifying the font name, using web fonts, or using Google Fonts. Each method has its advantages and disadvantages, which you need to choose based on your needs.
The above is the detailed content of How to set the font set by css. For more information, please follow other related articles on the PHP Chinese website!