Home  >  Article  >  Web Front-end  >  How Can I Import Multiple Font Weights with a Single @font-face Declaration?

How Can I Import Multiple Font Weights with a Single @font-face Declaration?

DDD
DDDOriginal
2024-11-13 13:49:02464browse

How Can I Import Multiple Font Weights with a Single @font-face Declaration?

Querying Multiple Font Weights with a Single @font-face Declaration

Importing multiple font variants with different weights can be tedious when relying on individual @font-face blocks. CSS offers a solution that combines these variants into a single declaration.

Implementing a Single @font-face Query

The key to achieving this is the specific syntax of the @font-face declaration, which accepts a colon-separated list of font weight, font style, and font family properties. Here's an example:

@font-face {
  font-family: "Klavika";
  src: url("Klavika-Bold.otf") weight:bold, url("Klavika-Light.otf") weight:light;
}

By specifying the weight, style, and family properties in this manner, multiple font variants can be imported simultaneously.

Example Usage

This method allows for flexible styling with individual font weights:

h1 { font-weight:bold; font-family: Klavika; }
p { font-weight:light; font-family: Klavika; }

Additionally, you can leverage the standard @font-face syntax to specify other font properties, such as src and format.

Further Reading

For an exhaustive exploration of this feature, refer to the provided online resource, which offers a more detailed exposition and additional examples.

The above is the detailed content of How Can I Import Multiple Font Weights with a Single @font-face Declaration?. 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