
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 計量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 內聯塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - 清除浮動
- CSS - 浮動
- CSS - 箭頭
- CSS - 尺寸調整
- CSS - 引號
- CSS - 順序
- CSS - 位置
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 轉換
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 覆蓋層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪輯
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- CSS - 內嵌
- CSS - 隔離
- CSS - 滾動溢位
- CSS - Justify Items
- CSS - Justify Self
- CSS - 製表符大小
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大塊尺寸
- CSS - 最小塊尺寸
- CSS - 混合模式
- CSS - 最大內聯尺寸
- CSS - 最小內聯尺寸
- CSS - 偏移量
- CSS - 重音顏色
- CSS - 使用者選擇
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 圖層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - 重要
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - 游標顏色
- CSS - 文字陰影
- CSS - 文字
- CSS - 2d 轉換
- CSS - 3d 轉換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特異性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - font 屬性
CSS font 是一個簡寫屬性,用於一次設定多個字型屬性,例如 font-size、font-variant、font-weight、font-size、font-family 等。font-size 和 font-family 是必需的引數。如果某些值缺失,則使用預設值。
語法
font: font-style font-variant font-weight font-size/line-height font-family | caption | icon | menu | message-box | small-caption | status-bar | initial | inherit;
屬性值
值 | 描述 |
---|---|
font-style | 它指定字型樣式。預設值為 normal。 |
font-variant | 它指定字型變體。預設值為 normal。 |
font-weight | 它指定字型粗細。預設值為 normal。 |
font-size | 它指定字型大小和行高。預設值為 normal。 |
font-family | 它指定字體系列。預設值取決於瀏覽器。 |
caption | 它使用帶標題控制元件(如按鈕、下拉選單等)使用的字型。 |
icon | 它使用圖示標籤使用的字型。 |
menu | 它使用下拉選單使用的字型。 |
message-box | 它使用對話方塊使用的字型。 |
small-caption | 這是標題字型的較小版本。 |
status-bar | 它使用狀態列使用的字型。 |
initial | 這將屬性設定為其預設值。 |
inherit | 這從父元素繼承屬性。 |
CSS 字型屬性示例
以下示例說明了font 屬性及其各個組成部分。
設定文字的字型樣式
要設定文字的字型樣式,我們使用font 屬性的font-style 元件。可以為 font-style 元件賦予不同的值,相應地文字將被修改。在以下示例中,italic 值已與 font 屬性的 font-style 元件一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font-style: italic; } </style> </head> <body> <h2>CSS font property</h2> <p>This text is without the font style property.</p> <div id="font"> This text is shows the font-style property. </div> </body> </html>
設定文字的字型變體
要設定文字的字型變體,它指定文字是否應以小寫字型顯示,我們使用font 屬性的font-variant 元件。在以下示例中,small-caps 值已與 font 屬性的 font-variant 元件一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font-variant: small-caps; } </style> </head> <body> <h2>CSS font property</h2> <p>This text is without the font variant property.</p> <div id="font"> This text shows the font variant property. </div> </body> </html>
設定文字的字型粗細
要設定文字的字型粗細,它指定文字應有多粗,我們使用font 屬性的font-weight 元件。可以為 font-weight 元件賦予不同的值,相應地文字將被修改。在以下示例中,bolder 值已與 font 屬性的 font-weight 元件一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font-weight: bolder; } </style> </head> <body> <h2>CSS font property</h2> <p>This text is without the font weight property.</p> <div id="font"> This text shows the font weight property. </div> </body> </html>
設定文字的字型大小
要設定文字的字型大小,它指定文字應有多大,我們使用font 屬性的font-size 元件。可以為 font-size 元件賦予不同的值,相應地文字將被修改。在以下示例中,larger 值已與 font 屬性的 font-size 元件一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font-size: larger; } </style> </head> <body> <h2>CSS font property</h2> <p>This text is without the font size property.</p> <div id="font"> This text shows the font size property. </div> </body> </html>
設定文字的字體系列
要設定文字的字體系列,它指定文字的排版,我們使用font 屬性的font-family 元件。可以為 font-family 元件賦予不同的值,相應地文字將被修改。在以下示例中,Impact 值已與 font 屬性的 font-family 元件一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font-family: Impact; } </style> </head> <body> <h2>CSS font property</h2> <p>This text is without the font family property.</p> <div id="font"> This text shows the font family property. </div> </body> </html>
一次設定所有值
要一次設定所有值(font-style、font-variant、font-weight、font-size 和 font-family),我們使用font 屬性。在以下示例中,字型樣式為 italic,字型變體為 small-caps,字型粗細為 bold,字型大小為 30px,字體系列為 Times New Romans。
示例
<!DOCTYPE html> <html> <head> <style> #font { font:italic small-caps bold 30px Times New Romans; } </style> </head> <body> <h2>CSS font property</h2> <p>This is normal text.</p> <div id="font"> This text shows the font property. </div> </body> </html>
設定標題的字型
要設定按鈕、下拉選單等帶標題控制元件的字型,我們使用font 屬性的 caption 值。在以下示例中,caption 值已與 font 屬性一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font: caption; } </style> </head> <body> <h2>CSS font property</h2> <div id="font"> The caption value is used for captions. </div> </body> </html>
設定圖示標籤的字型
要設定圖示標籤使用的字型,我們使用font 屬性的 icon 值。在以下示例中,icon 值已與 font 屬性一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font:icon; } </style> </head> <body> <h2>CSS font property</h2> <div id="font"> This icon value is used for icon labels. </div> </body> </html>
設定下拉選單的字型
要設定下拉選單使用的字型,我們使用font 屬性的 menu 值。在以下示例中,menu 值已與 font 屬性一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font:menu; } </style> </head> <body> <h2>CSS font property</h2> <div id="font"> The menu value is used for dropdown menus. </div> </body> </html>
設定訊息框的字型
要設定訊息框的字型,我們使用font 屬性的 message-box 值。在以下示例中,message-box 值已與 font 屬性一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font:message-box; } </style> </head> <body> <h2>CSS font property</h2> <div id="font"> The message box is value is used for dialog boxes. </div> </body> </html>
設定標題的小字型
要設定標題的小字型,我們使用font 屬性的 small-caption 值。在以下示例中,small-caption 值已與 font 屬性一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font:small-caption; } </style> </head> <body> <h2>CSS font property</h2> <div id="font"> The small-caption value is a smaller version of caption value. </div> </body> </html>
設定狀態列的字型
要設定狀態列的字型,我們使用font 屬性的 status-bar 值。在以下示例中,status-bar 值已與 font 屬性一起使用。
示例
<!DOCTYPE html> <html> <head> <style> #font { font:status-bar; } </style> </head> <body> <h2>CSS font property</h2> <div id="font"> The status-bar value is used for status bars. </div> </body> </html>
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
font | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |