×
HTML标签列表(字母排序)HTML标签列表(功能排序)HTML 全局属性HTML 事件属性HTML 画布HTML 音频/视频HTML 有效 DOCTYPESHTML 颜色名HTML 拾色器HTML 颜色混搭HTML 字符集HTML ASCIIHTML ISO-8859-1HTML 符号实体HTML URL 编码HTML 语言代码HTML 状态消息HTML GET/ POST方法Px、Em 换算工具键盘快捷键

HTML 标签

<!--...--><!DOCTYPE><a><abbr><acronym><address><applet><area><article><aside><audio><b><base><basefont><bdi><bdo><big><blockquote><body><br><button><canvas><caption><center><cite><code><col><colgroup><command><datalist><dd><del><details><dfn><dialog><dir><div><dl><dt><em><embed><fieldset><figcaption><figure><font><footer><form><frame><frameset><head><header><hgroup><h1><hr><i><iframe><img><input><ins><kbd><keygen><label><legend><li><link><map><mark><menu><meta><meter><nav><noframes><noscript><object><ol><optgroup><option><output><p><param><pre><html><progress><q><rp><rt><ruby><s><samp><script><section><select><small><source><span><strike><strong><style><sub><summary><sup><table><tbody><td><textarea><tfoot><th><thead><time><title><tr><track><tt><u><ul><var><video><wbr>

HTML canvas font 属性


HTML5 <canvas> 参考手册HTML5 <canvas> 参考手册


实例

在画布上写一段 30 像素的文本,使用的字体是 "Arial":

YourbrowserdoesnotsupporttheHTML5canvastag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="30px Arial";
ctx.fillText("Hello World",10,50);

尝试一下 »

浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 font 属性。

注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。


定义和用法

font 属性设置或返回画布上文本内容的当前字体属性。

font 属性使用的语法与 CSS font 属性 相同。

默认值: 10px sans-serif
JavaScript 语法: context.font="italic small-caps bold 12px arial";

属性值

描述
font-style 规定字体样式。可能的值:
  • normal
  • italic
  • oblique
font-variant 规定字体变体。可能的值:
  • normal
  • small-caps
font-weight 规定字体的粗细。可能的值:
  • normal
  • bold
  • bolder
  • lighter
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900
font-size/line-height 规定字号和行高,以像素计。
font-family 规定字体系列。
caption 使用标题控件的字体(比如按钮、下拉列表等)。
icon 使用用于标记图标的字体。
menu 使用用于菜单中的字体(下拉列表和菜单列表)。
message-box 使用用于对话框中的字体。
small-caption 使用用于标记小型控件的字体。
status-bar 使用用于窗口状态栏中的字体。

HTML5 <canvas> 参考手册HTML5 <canvas> 参考手册


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)