文字排版 (Typography)
用於 Bootstrap 文字排版的文件和範例,包括全域設定、標題、主體文本、列表和更多。
全域設定
Bootstrap 設定基本的全域顯示、文字排版和連結樣式。當需要更多的控制時,查看 文本工具類型。
- 為每個作業系統和設備選定最佳
font-family
的 原生字體堆疊。 - 為了獲得一個包容和易用的類型縮放,我們使用瀏覽器預設
font-size
(一般為16px)因此可在必要時自訂瀏覽器預設值。 - 使用
$font-family-base
、$font-size-base
和$line-height-base
屬性作為<body>
的文字排版基礎。 $link-color
設定全域連結顏色。- 使用
$body-bg
以在<body>
上設定background-color
(預設為 #fff)。
可以在 _reboot.scss
中找到上述格式,且在 _variables.scss
定義了全域變數。確保在 rem
中設置 $font-size-base
。
標題
全部的 HTML 標題從 <h1>
到 <h6>
均可使用。
Heading | Example |
---|---|
<h1></h1>
|
h1. Bootstrap heading |
<h2></h2>
|
h2. Bootstrap heading |
<h3></h3>
|
h3. Bootstrap heading |
<h4></h4>
|
h4. Bootstrap heading |
<h5></h5>
|
h5. Bootstrap heading |
<h6></h6>
|
h6. Bootstrap heading |
<h1>h1. Bootstrap heading</h1>
<h2>h2. Bootstrap heading</h2>
<h3>h3. Bootstrap heading</h3>
<h4>h4. Bootstrap heading</h4>
<h5>h5. Bootstrap heading</h5>
<h6>h6. Bootstrap heading</h6>
當你想匹配某一標題的字體樣式,但不能直接使用 HTML 元素時,使用 .h1
到 .h6
的類別。
h1. Bootstrap heading
h2. Bootstrap heading
h3. Bootstrap heading
h4. Bootstrap heading
h5. Bootstrap heading
h6. Bootstrap heading
<p class="h1">h1. Bootstrap heading</p>
<p class="h2">h2. Bootstrap heading</p>
<p class="h3">h3. Bootstrap heading</p>
<p class="h4">h4. Bootstrap heading</p>
<p class="h5">h5. Bootstrap heading</p>
<p class="h6">h6. Bootstrap heading</p>
自定義標題
使用通用類別重現 Bootstrap 3.0 中的小標題文本。
Fancy display heading With faded secondary text
<h3>
Fancy display heading
<small class="text-muted">With faded secondary text</small>
</h3>
顯示標題
一般的標題元素能在頁面內容繁多時發揮最佳作用。當你需要突出一個標題時,請考慮使用 display heading 以獲得更大、更細、稍具有風格化的標題樣式。
<h1 class="display-1">Display 1</h1>
<h1 class="display-2">Display 2</h1>
<h1 class="display-3">Display 3</h1>
<h1 class="display-4">Display 4</h1>
<h1 class="display-5">Display 5</h1>
<h1 class="display-6">Display 6</h1>
顯示標題經由 $display-font-sizes
Sass map 和兩個變數 $display-font-weight
及 $display-line-height
的配置。
$display-font-sizes: (
1: 5rem,
2: 4.5rem,
3: 4rem,
4: 3.5rem,
5: 3rem,
6: 2.5rem
);
$display-font-weight: 300;
$display-line-height: $headings-line-height;
前導主題
使用 .lead
讓一個段落脫穎而出。
This is a lead paragraph. It stands out from regular paragraphs.
<p class="lead">
This is a lead paragraph. It stands out from regular paragraphs.
</p>
行內文本元素
使用行內 HTML5 元素的格式。
You can use the mark tag to highlight text.
This line of text is meant to be treated as deleted text.
This line of text is meant to be treated as no longer accurate.
This line of text is meant to be treated as an addition to the document.
This line of text will render as underlined.
This line of text is meant to be treated as fine print.
This line rendered as bold text.
This line rendered as italicized text.
<p>You can use the mark tag to <mark>highlight</mark> text.</p>
<p><del>This line of text is meant to be treated as deleted text.</del></p>
<p><s>This line of text is meant to be treated as no longer accurate.</s></p>
<p><ins>This line of text is meant to be treated as an addition to the document.</ins></p>
<p><u>This line of text will render as underlined.</u></p>
<p><small>This line of text is meant to be treated as fine print.</small></p>
<p><strong>This line rendered as bold text.</strong></p>
<p><em>This line rendered as italicized text.</em></p>
請注意,這些標籤應用於語義目的:
<mark>
代表被標記或是重點強調的文本,以供參考或標記。<small>
代表旁註和小字體,例如版權聲明和版權文字。<s>
代表不再相關或不再準確的元素。<u>
代表一定範圍的行內文字,應指示其具有非文本註釋的方式呈現。
如果你只是想要在文本上加入樣式,你應該改使用以下類別:
.mark
與<mark>
呈現相同樣式。.small
與<small>
呈現相同樣式。.text-decoration-underline
與<u>
呈現相同樣式。.text-decoration-line-through
與<s>
呈現相同樣式。
當以上未顯示時,請自行使用 HTML5 中的<b>
和 <i>
。<b>
旨在突出顯示單詞或短語,而不會增加重要性,而 <i>
主要用於語音,技術術語等。
文本通用類別
改變文字對齊、變換、樣式、字重、行高、裝飾線和顏色可以透過 文本 通用類別 和 顏色 通用類別。
縮寫
對縮寫和字母字首縮寫使用 HTML <abbr>
元素以 Hover 方式顯示縮寫的擴增內容。縮寫具有預設的底線和説明游標,透過懸停和輔助性技術幫助使用者提供額外的內容。
縮寫字加入 .initialism
可將字體略為縮小。
attr
HTML
<p><abbr title="attribute">attr</abbr></p>
<p><abbr title="HyperText Markup Language" class="initialism">HTML</abbr></p>
引用
用於文件中引用來自另一個來源的內容。在 HTML 周圍使用 <blockquote class="blockquote">
。
A well-known quote, contained in a blockquote element.
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote>
引用來源
HTML 規範要求將 blockquote 歸屬於 <blockquote>
之外。當提供來源歸屬,需要將 <blockquote>
包在 <figure>
之內,並且使用 <figure>
和加上 .blockquote-footer
類別的 <figcaption>
或是一個區塊元素(例如:<p>
)。還要確保將來源的名稱包在 <cite>
中。
<figure>
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote>
<figcaption class="blockquote-footer">
Someone famous in <cite title="Source Title">Source Title</cite>
</figcaption>
</figure>
對齊
使用文字通用類別來更改 blockquote 的對齊方式。
<figure class="text-center">
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote>
<figcaption class="blockquote-footer">
Someone famous in <cite title="Source Title">Source Title</cite>
</figcaption>
</figure>
<figure class="text-end">
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote>
<figcaption class="blockquote-footer">
Someone famous in <cite title="Source Title">Source Title</cite>
</figcaption>
</figure>
列表
無樣式
刪除預設的 list-style
和列表項目上的左 margin(僅限直接子項)。僅適用於直接子項目列表,這意味著你需要為巢狀的列表添加類別。
- This is a list.
- It appears completely unstyled.
- Structurally, it's still a list.
- However, this style only applies to immediate child elements.
- Nested lists:
- are unaffected by this style
- will still show a bullet
- and have appropriate left margin
- This may still come in handy in some situations.
<ul class="list-unstyled">
<li>This is a list.</li>
<li>It appears completely unstyled.</li>
<li>Structurally, it's still a list.</li>
<li>However, this style only applies to immediate child elements.</li>
<li>Nested lists:
<ul>
<li>are unaffected by this style</li>
<li>will still show a bullet</li>
<li>and have appropriate left margin</li>
</ul>
</li>
<li>This may still come in handy in some situations.</li>
</ul>
行內
移除了列表編號並增加些許 margin,結合使用 .list-inline
和 .list-inline-item
。
- This is a list item.
- And another one.
- But they're displayed inline.
<ul class="list-inline">
<li class="list-inline-item">This is a list item.</li>
<li class="list-inline-item">And another one.</li>
<li class="list-inline-item">But they're displayed inline.</li>
</ul>
描述型列表對齊
通過使用我們網格系統定義的類別(或是語意 mixins)將項目和說明水平對齊。對於較長的術語,你可選擇性加上 .text-truncate
來用 … 取代多餘內容。
- Description lists
- A description list is perfect for defining terms.
- Term
-
Definition for the term.
And some more placeholder definition text.
- Another term
- This definition is short, so no extra paragraphs or anything.
- Truncated term is truncated
- This can be useful when space is tight. Adds an ellipsis at the end.
- Nesting
-
- Nested definition list
- I heard you like definition lists. Let me put a definition list inside your definition list.
<dl class="row">
<dt class="col-sm-3">Description lists</dt>
<dd class="col-sm-9">A description list is perfect for defining terms.</dd>
<dt class="col-sm-3">Term</dt>
<dd class="col-sm-9">
<p>Definition for the term.</p>
<p>And some more placeholder definition text.</p>
</dd>
<dt class="col-sm-3">Another term</dt>
<dd class="col-sm-9">This definition is short, so no extra paragraphs or anything.</dd>
<dt class="col-sm-3 text-truncate">Truncated term is truncated</dt>
<dd class="col-sm-9">This can be useful when space is tight. Adds an ellipsis at the end.</dd>
<dt class="col-sm-3">Nesting</dt>
<dd class="col-sm-9">
<dl class="row">
<dt class="col-sm-4">Nested definition list</dt>
<dd class="col-sm-8">I heard you like definition lists. Let me put a definition list inside your definition list.</dd>
</dl>
</dd>
</dl>
響應式文字排版
在 Bootstrap 5 中,預設情況下我們已經可以響應字體大小,讓文本更自然的跨裝置進行縮放。可以參考 RFS page 查看他是如何運作的。
Sass
Variables
Headings have some dedicated variables for sizing and spacing.
$headings-margin-bottom: $spacer / 2;
$headings-font-family: null;
$headings-font-style: null;
$headings-font-weight: 500;
$headings-line-height: 1.2;
$headings-color: null;
Miscellaneous typography elements covered here and in Reboot also have dedicated variables.
$lead-font-size: $font-size-base * 1.25;
$lead-font-weight: 300;
$small-font-size: .875em;
$sub-sup-font-size: .75em;
$text-muted: $gray-600;
$initialism-font-size: $small-font-size;
$blockquote-margin-y: $spacer;
$blockquote-font-size: $font-size-base * 1.25;
$blockquote-footer-color: $gray-600;
$blockquote-footer-font-size: $small-font-size;
$hr-margin-y: $spacer;
$hr-color: inherit;
$hr-height: $border-width;
$hr-opacity: .25;
$legend-margin-bottom: .5rem;
$legend-font-size: 1.5rem;
$legend-font-weight: null;
$mark-padding: .2em;
$dt-font-weight: $font-weight-bold;
$nested-kbd-font-weight: $font-weight-bold;
$list-inline-padding: .5rem;
$mark-bg: #fcf8e3;
Mixins
There are no dedicated mixins for typography, but Bootstrap does use Responsive Font Sizing (RFS).