textBaseline Özelliği
textBaseline özelliği,
fillText
veya strokeText
yöntemiyle çizilen metnin dikey hizalamasını belirler.
Şu değerlerden birini alır: top,
hanging, middle, alphabetic (varsayılan),
ideographic, bottom (değerlerin anlamı için
www.w3schools.com/tags/canvas_textbaseline.asp adresine bakın).
Sözdizimi
bağlam.textBaseline = değer;
Örnek
Metne üst çizgiden dikey hizalama verelim:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline = 'top';
ctx.fillText('text', 80, 100);
:
Örnek
Şimdi de metne alt çizgiden dikey hizalama verelim:
<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.strokeStyle = 'red';
ctx.moveTo(0, 100);
ctx.lineTo(400, 100);
ctx.stroke();
ctx.font="14px Arial";
ctx.textBaseline="bottom";
ctx.fillText('text', 80, 100);
: