跳至內容

排版

為長文內容提供語意化的排版樣式。

typography 外掛提供一組 prose-* shortcut,用合理的排版預設值來為長文 HTML 內容(文章、部落格文章、說明文件)設定樣式。

sh
pnpm add -D @pikacss/plugin-typography
sh
npm install -D @pikacss/plugin-typography
sh
yarn add -D @pikacss/plugin-typography
ts
import { defineEngineConfig } from '@pikacss/core'
import { typography } from '@pikacss/plugin-typography'

export default defineEngineConfig({
	plugins: [typography()],
})

可用的 shortcut:

Shortcut用途
prose-base其他 prose-* shortcut 共用的基礎 prose 容器樣式
prose基礎 prose 樣式,套用所有元件樣式
prose-paragraphs段落間距與行高
prose-links連結顏色與底線
prose-emphasis粗體與斜體樣式
prose-kbd鍵盤輸入樣式
prose-lists有序與無序清單樣式
prose-hr水平分隔線樣式
prose-headings標題大小與間距
prose-quotes區塊引言樣式
prose-media圖片與影片樣式
prose-code行內程式碼與程式碼區塊樣式
prose-tables表格樣式

尺寸變體:

Shortcut用途
prose-sm小型 prose 尺寸
prose-lg大型 prose 尺寸
prose-xl特大 prose 尺寸
prose-2xl雙倍特大 prose 尺寸

使用方式:

typography 的 shortcut 就是一般的 pika() 輸入。舉例來說,你可以像這樣套用一個聚焦的模組 shortcut:

ts
const articleLinksClassName = pika('prose-links')
css
@layer utilities {
  .pk-a {
    color: var(--pk-prose-color-body);
  }
  .pk-b {
    max-width: 65ch;
  }
  .pk-c {
    font-size: 1rem;
  }
  .pk-d {
    line-height: 1.75;
  }
  .pk-e > :first-child {
    margin-top: 0;
  }
  .pk-f > :last-child {
    margin-bottom: 0;
  }
  .pk-g a {
    color: var(--pk-prose-color-links);
  }
  .pk-h a {
    text-decoration: underline;
  }
  .pk-i a {
    font-weight: 500;
  }
  .pk-j a strong {
    color: inherit;
  }
  .pk-k a code {
    color: inherit;
  }
}

Prose 的顏色角色使用 --pk-prose-color-* CSS 變數,例如 --pk-prose-color-body--pk-prose-color-links,以及 --pk-prose-color-headings。鍵盤按鍵陰影則使用 --pk-prose-kbd-shadows

設定

透過引擎設定中最上層的 typography key 來設定這個外掛。

屬性說明
variables巢狀於 typography 底下。針對已註冊的 prose 變數的 CSS 變數覆寫,包含 --pk-prose-color-* 這一組與 --pk-prose-kbd-shadows
ts
import { defineEngineConfig } from '@pikacss/core'
import { typography } from '@pikacss/plugin-typography'

export default defineEngineConfig({
	typography: {
		variables: {
			'--pk-prose-color-links': '#2563eb',
		},
	},
	plugins: [typography()],
})

完整的型別簽章與預設值請見 API 參考 — Plugin Typography

下一步

  • 圖示:透過 Iconify 整合圖示。
  • 字型:網頁字型載入。