CSS: Wie binde ich eine gedownloadete Schriftart ein?

2 Antworten

Vom Fragesteller als hilfreich ausgezeichnet
@font-face {
 font-family: myFirstFont;
 src: url(sansation_light.woff);
 }

https://www.w3schools.com/css/css3_fonts.asp
Sozialkompetenz 
Fragesteller
 09.05.2021, 03:01

Hey es hat funktioniert danke!!! Kriegst die hilfreichste :D

0

Für optimalen Support in allen gängigen Browsern:

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: url('../fonts/roboto-v27-latin-regular.eot'); /* IE9 Compat Modes */
  src: local(''),
       url('../fonts/roboto-v27-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
       url('../fonts/roboto-v27-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
       url('../fonts/roboto-v27-latin-regular.woff') format('woff'), /* Modern Browsers */
       url('../fonts/roboto-v27-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
       url('../fonts/roboto-v27-latin-regular.svg#Roboto') format('svg'); /* Legacy iOS */
}

Und wenn du damit leben kannst, dass die Schriftart in einigen älteren Browsern evtl. nicht richtig angezeigt wird:

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 400;
  src: local(''),
       url('../fonts/roboto-v27-latin-regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
       url('../fonts/roboto-v27-latin-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}

TTF-Dateien im Browser zu verwenden ist eher unüblich. Normalerweise wandelt man die in die gängigen Formate WOFF, WOFF2, SVG, etc. um: https://www.fontsquirrel.com/tools/webfont-generator

Ich hoffe, ich konnte helfen. :)

Woher ich das weiß:Berufserfahrung
Sozialkompetenz 
Fragesteller
 10.05.2021, 04:16

Wieso unüblich? Werde ich mit ttf auf Probleme stoßen? Wer kann das dann nicht anzeigen?

0
Niklas  10.05.2021, 08:08
@Sozialkompetenz

Es wird zu Kompatibilitätsproblemen kommen. Daher auch die Verlinkung zum Generator, der einen ttf-Font in die gängigen Formate umwandelt. Ich bin mir nicht sicher, ob einen reinen ttf-Font überhaupt ein Browser darstellen kann.

0