HTML教程
HTML5教程
HTML参考手册

HTML canvas font 属性

在画布上写一段 30 像素的文本,使用的字体是 "Arial":
您的浏览器不支持HTML5 canvas标签.
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.font="30px Arial";
ctx.fillText("Hello World",10,50);

浏览器支持

Internet Explorer Firefox Opera Google Chrome Safari
Internet Explorer 9、Firefox、Opera、Chrome 和 Safari 支持 font 属性。
注意:Internet Explorer 8 及之前的版本不支持 <canvas> 元素。

定义和用法

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 使用用于窗口状态栏中的字体。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4