English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Referenzhandbuch

HTML-Tag-Übersicht

HTML canvas font-Eigenschaft

font ist Canvas 2D API beschreibt die Attribute der aktuellen Font-Style, wenn Text gezeichnet wird. Verwendet wie die CSS Font-Regeln gleiche Zeichenkettengrößen.

HTML canvas Reference Manual

Online-Beispiel

Schreiben Sie einen Text auf die Leinwand 30 Pixel Text, der die Schriftart "Arial" verwendet:

Ihr Browser unterstützt keine HTML5 canvas-Tag.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8>
<title>HTML canvas font-Eigenschaft verwenden-Grund教程(oldtoolbag.com)</<title>
</<head>
<body>
<canvas id="myCanvas" width="300" height="15" style="border:1px fest #d3d3d3>
Ihr Browser unterstützt keine HTML5 canvas-Tag.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="30px Arial";
ctx.fillText("Grund教程 oldtoolbag.com",10,50);
</script>
</body>
</html>
Testen Sie es heraus ‹/›

Browserkompatibilität

IEFirefoxOperaChromeSafari

Internet Explorer 9Firefox, Opera, Chrome und Safari unterstützen Font Eigenschaft.

Hinweis:Internet Explorer 8 frühere Versionen unterstützen den <canvas>-Element nicht.

Definition und Verwendung

setzt oder gibt die aktuellen Font-Eigenschaften des Textinhalts auf der Leinwand zurück.

Die Syntax der Font-Eigenschaft entspricht CSS Font-Eigenschaft identisch.

Standardwert:10px sans-serif
JavaScript Syntax:context.font="italic small-caps bold 12px arial";

Attribute Value

ValueDescription
font-styleSpecify the font style. Possible values:
  • normal

  • italic

  • oblique

font-variantSpecify the font variant. Possible values:
  • normal

  • small-caps

font-weightSpecify the font weight. Possible values:
  • normal

  • bold

  • bolder

  • lighter

  • 100

  • 200

  • 300

  • 400

  • 500

  • 600

  • 700

  • 800

  • 900

font-size/line-heightSpecify the font size and line height in pixels.
font-familySpecify the font family.
captionUse the font for title controls (such as buttons, drop-down lists, etc.).
iconUse the font for marking icons.
menuUse the font for menus (drop-down lists and menu lists).
message-boxUse the font for dialog boxes.
small-captionUse the font for marking small controls.
status-barUse the font for the window status bar.
HTML canvas Reference Manual