Home >Web Front-end >CSS Tutorial >How to change font in css

How to change font in css

王林
王林Original
2021-05-20 15:21:055581browse

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; }].

How to change font in css

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:

How to change font in css

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!

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