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

javascriptbağlam.textBaseline = değer;

Örnek

Metne üst çizgiden dikey hizalama verelim:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptconst 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:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptconst 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); 

Результат:

Ayrıca Bakınız

  • metni yatay olarak hizalamak için textAlign özelliği,
  • yazı tipi boyutunu ve türünü belirlemek için font özelliği