การจัดตำแหน่งของตัวอักษร หรือประโยคด้วยภาษา CSS นั้นจะใช้คำสั่ง text-align ในการจัดตำแหน่งตามที่ต้องการ เช่น ซ้าย, ขวา หรือตรงกลาง
ภาพรวมของคำสั่ง text-align
1. ใช้คำสั่ง text-align:<VALUE> ในการกำหนดตำแหน่งของตัวอักษร หรือประโยค
2. ระบุค่า left สำหรับกำหนดให้ตัวอักษร หรือประโยคชิดตำแหน่งทางซ้าย
3. ระบุค่า center สำหรับกำหนดให้ตัวอักษร หรือประโยคชิดตำแหน่งตรงกลาง
4. ระบุค่า right สำหรับกำหนดให้ตัวอักษร หรือประโยคชิดตำแหน่งทางขวา
ตัวอย่างโปรแกรม
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>amplysoft.com รับเขียนเว็บ รับทำเว็บ เรียนเขียนโปรแกรม</title></head><body><style type="text/css">.content { border:solid 1px #cccccc; padding:3px; clear:both; width:300px; margin:3px;}#text_center { text-align:center; }#text_right { text-align:right; }#text_left { text-align:left; }</style><div id='text_left' class='content'>Text Align Left</div><div id='text_right' class='content'>Text Align Right</div><div id='text_center' class='content'>Text Align Center</div></body></html> |
ผลลัพธ์


