text-align: left | right | center | justify | start | end | match-parent;
| 值 | 說明 |
|---|---|
left | 靠左(預設,LTR 書寫模式) |
right | 靠右 |
center | 置中 |
justify | 兩端對齊(調整字詞間距) |
start/end | 邏輯屬性,隨 writing-mode 自動對應左右(CSS3) |

text-align 僅對 區塊級容器 內的 行內/行內區塊內容 生效。直接對 <img>(行內元素)設定無效,需對其父區塊設定。
<!-- 錯誤:img 仍靠右 -->
<p style="text-align:right;">
<img src="cat.gif" style="text-align:center;" alt="">
</p>
<!-- 正確:父層置中 -->
<p style="text-align:center;">
<img src="cat.gif" alt="">
</p>

text-align 可繼承。父層設定後,所有子孫行內內容皆受影響(Opera 下表頭 th 可能不繼承,需單獨設定)。

body { text-align: center; } /* IE5/Quirks 模式置中 */
#wrap {
width: 960px;
margin: 0 auto; /* 標準模式水平置中 */
text-align: left; /* 內容文字恢復靠左 */
}
不同瀏覽器表現差異:

.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 1rem;
}
/* 配合 Flexbox/Grid 進行內部對齊,不再依賴 text-align 置中版面 */