The way to change the font in css is to add the font-family attribute to the font and set the required font attributes, such as [p.serif{font-family:"Times New Roman",Times,serif; }].
The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.
If we want to change the font of an element in CSS, it is actually very simple. We can use the font-family attribute.
Common attribute values:
family-name and generic-family A priority list for the font family name or/and class family name of an element. Default: Depends on browser.
inherit Specifies that the font family should be inherited from the parent element.
Let’s take a look at the following piece of code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> p.serif{font-family:"Times New Roman",Times,serif;} p.sansserif{font-family:Arial,Helvetica,sans-serif;} </style> </head> <body> <h1>CSS font-family</h1> <p class="serif">这一段的字体是 Times New Roman </p> <p class="sansserif">这一段的字体是 Arial.</p> </body> </html>
Running effect:
Related videos Tutorial sharing: css video tutorial
The above is the detailed content of How to change font in css. For more information, please follow other related articles on the PHP Chinese website!