ข้อมูลอ้างอิงHTML

HTML โดยตัวอักษร HTML ตามหมวดหมู่ รองรับ HTML Browser แอตทริบิวต์ HTML HTML Global Attributes เหตุการณ์ HTML HTML สี HTML Canvas HTML เสียง/วิดีโอ ชุดอักขระ HTML HTML Doctypes การเข้ารหัส URL HTML รหัสภาษา HTML รหัสประเทศ HTML ข้อความ HTTP วิธี HTTP ตัวแปลง PX เป็น EM แป้นพิมพ์ลัด


ผ้าใบ HTML textAlign Property

❮ การอ้างอิงผ้าใบ HTML

ตัวอย่าง

สร้างเส้นสีแดงในตำแหน่ง 150 ตำแหน่ง 150 คือจุดยึดสำหรับข้อความทั้งหมดที่กำหนดไว้ในตัวอย่างด้านล่าง ศึกษาผลกระทบของค่าคุณสมบัติ textAlign แต่ละค่า:

YourbrowserdoesnotsupporttheHTML5canvastag.

จาวาสคริปต์:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

// Create a red line in position 150
ctx.strokeStyle = "red";
ctx.moveTo(150, 20);
ctx.lineTo(150, 170);
ctx.stroke();

ctx.font = "15px Arial";

// Show the different textAlign values
ctx.textAlign = "start";
ctx.fillText("textAlign=start", 150, 60);
ctx.textAlign = "end";
ctx.fillText("textAlign=end", 150, 80);
ctx.textAlign = "left";
ctx.fillText("textAlign=left", 150, 100);
ctx.textAlign = "center";
ctx.fillText("textAlign=center", 150, 120);
ctx.textAlign = "right";
ctx.fillText("textAlign=right", 150, 140);

รองรับเบราว์เซอร์

ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนคุณสมบัติอย่างสมบูรณ์

Property
textAlign Yes 9.0 Yes Yes Yes

ความหมายและการใช้งาน

คุณสมบัติ textAlign ตั้งค่าหรือส่งคืนการจัดตำแหน่งปัจจุบันสำหรับเนื้อหาข้อความ ตามจุดยึด

โดยปกติ ข้อความจะเริ่มต้นในตำแหน่งที่ระบุ อย่างไรก็ตาม หากคุณตั้งค่า textAlign="right" และวางข้อความในตำแหน่ง 150 หมายความว่าข้อความควร สิ้นสุดในตำแหน่ง 150

เคล็ดลับ:ใช้วิธีfillText()หรือ strokeText()เพื่อวาดและวางตำแหน่งข้อความบนผืนผ้าใบ

ค่าเริ่มต้น: เริ่ม
ไวยากรณ์ JavaScript: บริบท .textAlign="center|end|left|right|start";

มูลค่าทรัพย์สิน

Values Description Play it
start Default. The text starts at the specified position
end The text ends at the specified position
center The center of the text is placed at the specified position
left The text starts at the specified position
right The text ends at the specified position

❮ การอ้างอิงผ้าใบ HTML