這一組屬性專門處理文字外觀,從字體到行距、從大小寫到文字流向。
<div style="font: bold 14px 宋體; background-color: yellow;">
明月幾時有?把酒問青天。
</div>
可以一次帶入粗細、大小、字體等多項設定。子屬性包括:
font-family 字體名稱、font-weight 粗細(bold、bolder、lighter 或數值 100–900)、font-size 大小、font-style 樣式(italic、normal、oblique)、color 顏色。
text-align 控制水平對齊:center、left、right、justify。
text-decoration 控制文字裝飾:none、underline、overline、line-through、blink 的組合。其中 blink 在 IE 中無效果,Firefox 支援,實務上已全面被 CSS 動畫取代。
text-indent 設定首行縮排,text-transform 控制英文字母大小寫:lowercase、uppercase、capitalize(每字首字母大寫)、none。
<div style="text-align: left; text-decoration: line-through;
text-indent: 30px; text-transform: capitalize;
color: blue; font: bold italic 14px 宋體; background-color: yellow;">
文字內容
</div>
overflow 控制內容溢出時的行為:scroll(永遠顯示捲軸)、visible(不顯示但溢出部分可見)、auto(超出時才顯示)、hidden(超出部分裁掉)。
direction 設定內容流向:ltr(左至右)或 rtl(右至左)。這對阿拉伯文、希伯來文等由右至左書寫的語言是必要設定,中文頁面一般用不到。
<div style="font: 16px 宋體; width: 600px; height: 200px;
word-spacing: 5px; line-height: 20px;
direction: rtl; overflow: auto; background-color: yellow;">
文字內容
</div>
line-height 指定行高,word-spacing 設定字與字之間的間距。行高是中文排版最容易被忽略的一項——預設值往往過於緊湊,正文段落設在 1.6 到 1.8 之間閱讀體驗會明顯改善。若要調整中文字元間距,該用的是 letter-spacing,而非 word-spacing(後者作用在單字之間的空白)。