<!DOCTYPE html5><html lang="en"><head> <meta charset="UTF-8"> <title>CSS3-Canvas畫布(文本)</title> <script> window.onload=function () { var canvas=document.getElementById("canvas");//獲取canvas對象 var ctx=canvas.getContext("2d"); //建立二維的繪圖上下文對象 ctx.font="50px Georgia"; ctx.strokeStyle="lightgreen"; ctx.strokeText("斜風細雨不須歸",50,50);//無填充文本 //對齊方式 使用 ctx.fillStyle="lightpink"; ctx.fillText("人間有味是清歡",50,300);//有填充文本 } </script></head><body><h2>Canvas畫布(文本)</h2><canvas id="canvas" width="500" height="500" style="border:1px solid red "> 瀏覽器不支持canvas</canvas></body></html>