Komanda font-face

Komanda @font-face ļauj definēt lietotāja fontu, kura avots glabājas failā. Šo fontu pēc tam varēs pievienot, izmantojot īpašību font-family.

Sintakse

css@font-face {
  fonta nosaukums;
  fonta avota atrašanās vieta;
}

Piemērs

Atradīsim fontu mūsu lokālajā datorā:

html<body>
  This is Montserrat SemiBold.
</body>
css@font-face {
  font-family: "Montserrat SemiBold";
  src: local("Montserrat SemiBold");
}
  
body {
  font-family: "Montserrat SemiBold";
}

#elem {
  animation: anim 3s infinite;
  border: 1px solid black;
  width: 50px;
  height: 50px;
}

Результат:

Piemērs

Un tagad norādīsim fonta meklēšanai adresi attālā servera:

html<body>
  This is Bitstream Vera Serif Bold.
</body>
css@font-face {
  font-family: "Bitstream Vera Serif Bold";
  src: url("https://mdn.github.io/css-examples/web-fonts/VeraSeBd.ttf");
}
  
body {
  font-family: "Bitstream Vera Serif Bold", serif;
}

#elem {
  animation: anim 3s infinite;
  border: 1px solid black;
  width: 50px;
  height: 50px;
}

Результат: