Home >Web Front-end >CSS Tutorial >Can You Define Multiple Font Weights in a Single @font-face Query?

Can You Define Multiple Font Weights in a Single @font-face Query?

Susan Sarandon
Susan SarandonOriginal
2024-11-24 05:06:14637browse

Can You Define Multiple Font Weights in a Single @font-face Query?

Can Multiple Font Weights Be Defined with a Single @font-face Query?

The Klavika font comes in various weights and shapes. Can these be imported into CSS with a single @font-face query that specifies the weight?

Solution:

Introducing a versatile feature of @font-face, you can associate different styles and weights with a single font family name:

@font-face {
  font-family: "DroidSerif";
  src: url("DroidSerif-Regular-webfont.ttf") format("truetype");  /* Normal weight, normal style */
  src: url("DroidSerif-Italic-webfont.ttf") format("truetype"); /* Normal weight, italic style */
  src: url("DroidSerif-Bold-webfont.ttf") format("truetype");  /* Bold weight, normal style */
  src: url("DroidSerif-BoldItalic-webfont.ttf") format("truetype"); /* Bold weight, italic style */
}

You can now specify font-weight:bold or font-style:italic for different elements:

body { font-family:"DroidSerif", Georgia, serif; }

h1 { font-weight:bold; }

em { font-style:italic; }

strong em {
  font-weight:bold;
  font-style:italic;
}

For comprehensive details on this feature, refer to the official documentation.

Example:

[Example Pen](https://codepen.io/anon/pen/EjxVqv)

The above is the detailed content of Can You Define Multiple Font Weights in a Single @font-face Query?. 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