字體排印
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>
,都可用。
標題 | 範例 |
---|---|
<h1></h1> |
h1. Bootstrap 標題 |
<h2></h2> |
h2. Bootstrap 標題 |
<h3></h3> |
h3. Bootstrap 標題 |
<h4></h4> |
h4. Bootstrap 標題 |
<h5></h5> |
h5. Bootstrap 標題 |
<h6></h6> |
h6. Bootstrap 標題 |
<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>
.h1
到 .h6
類別也可用,用於您想要符合標題的字體樣式,但無法使用關聯的 HTML 元素時。
h1. Bootstrap 標題
h2. Bootstrap 標題
h3. Bootstrap 標題
h4. Bootstrap 標題
h5. Bootstrap 標題
h6. Bootstrap 標題
<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 中的小型次要標題文字。
精緻的顯示標題 帶有淡出的次要文字
<h3>
Fancy display heading
<small class="text-body-secondary">With faded secondary text</small>
</h3>
顯示標題
傳統標題元素設計為最適合用於您的頁面內容中。當您需要一個標題脫穎而出時,請考慮使用顯示標題,這是一種更大、稍微更具觀點的標題樣式。
<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>
顯示標題透過 Sass 地圖 $display-font-sizes
和兩個變數 $display-font-weight
和 $display-line-height
來設定。
顯示標題可透過兩個變數 $display-font-family
和 $display-font-style
來自訂。
$display-font-sizes: (
1: 5rem,
2: 4.5rem,
3: 4rem,
4: 3.5rem,
5: 3rem,
6: 2.5rem
);
$display-font-family: null;
$display-font-style: null;
$display-font-weight: 300;
$display-line-height: $headings-line-height;
導言
透過新增 .lead
讓段落顯著。
這是導言段落。它比一般段落顯著。
<p class="lead">
This is a lead paragraph. It stands out from regular paragraphs.
</p>
內嵌文字元素
常見內嵌 HTML5 元素的樣式。
你可以使用標記標籤來 重點標示 文字。
這行文字應視為已刪除文字。
這行文字應視為不再正確。
這行文字應視為新增至文件。
這行文字會顯示為底線。
這行文字應視為小字。
這行文字顯示為粗體。
這行文字顯示為斜體。
<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>
元素的樣式化實作,用於縮寫和首字母縮寫,可在滑鼠游標移入時顯示展開的版本。縮寫預設會有底線,並會在滑鼠游標移入時顯示說明游標,以提供額外的內容,並供輔助技術使用者使用。
將 .initialism
新增至縮寫,以使用較小的字體大小。
屬性
HTML
<p><abbr title="attribute">attr</abbr></p>
<p><abbr title="HyperText Markup Language" class="initialism">HTML</abbr></p>
區塊引用
用於在文件中引用來自其他來源的內容區塊。將 <blockquote class="blockquote">
包覆在任何 HTML 中作為引文。
一個著名的引文,包含在區塊引用元素中。
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote>
命名來源
HTML 規範要求區塊引用註解必須置於 <blockquote>
之外。提供註解時,請將 <blockquote>
包覆在 <figure>
中,並使用 <figcaption>
或具有 .blockquote-footer
類別的區塊層級元素(例如 <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>
對齊
依需要使用文字公用程式變更區塊引用的對齊方式。
一個著名的引文,包含在區塊引用元素中。
<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
和左邊距(僅限直接子項目)。這僅適用於直接子項目清單項目,表示您也需要為任何巢狀清單新增類別。
- 這是清單。
- 它看起來完全沒有設定樣式。
- 在結構上,它仍然是清單。
- 不過,此樣式僅適用於直接子元素。
- 巢狀清單
- 不受此樣式影響
- 仍會顯示項目符號
- 並有適當的左邊距
- 這在某些情況下可能仍然派得上用場。
<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
。
- 這是清單項目。
- 還有另一個。
- 但它們以內嵌方式顯示。
<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>
說明清單對齊
使用我們的網格系統的預定義類別(或語意混合)將術語和說明水平對齊。對於較長的術語,您可以選擇新增 .text-truncate
類別,以使用省略號截斷文字。
- 說明清單
- 說明清單非常適合定義術語。
- 術語
-
術語的定義。
以及一些其他佔位符號定義文字。
- 另一個術語
- 這個定義很短,所以沒有額外的段落或任何東西。
- 被截斷的術語被截斷了
- 當空間不足時,這會很有用。在結尾處加上省略號。
- 巢狀
-
- 巢狀定義清單
- 我聽說你喜歡定義清單。讓我將定義清單放入你的定義清單中。
<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 頁面 以了解其運作方式。
CSS
Sass 變數
標題有一些專門的變數用於調整大小和間距。
$headings-margin-bottom: $spacer * .5;
$headings-font-family: null;
$headings-font-style: null;
$headings-font-weight: 500;
$headings-line-height: 1.2;
$headings-color: inherit;
此處和 Reboot 中涵蓋的雜項字體排印元素也具有專門的變數。
$lead-font-size: $font-size-base * 1.25;
$lead-font-weight: 300;
$small-font-size: .875em;
$sub-sup-font-size: .75em;
// fusv-disable
$text-muted: var(--#{$prefix}secondary-color); // Deprecated in 5.3.0
// fusv-enable
$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;
// fusv-disable
$hr-bg-color: null; // Deprecated in v5.2.0
$hr-height: null; // Deprecated in v5.2.0
// fusv-enable
$hr-border-color: null; // Allows for inherited colors
$hr-border-width: var(--#{$prefix}border-width);
$hr-opacity: .25;
$vr-border-width: var(--#{$prefix}border-width);
$legend-margin-bottom: .5rem;
$legend-font-size: 1.5rem;
$legend-font-weight: null;
$dt-font-weight: $font-weight-bold;
$list-inline-padding: .5rem;
$mark-padding: .1875em;
$mark-color: $body-color;
$mark-bg: $yellow-100;
Sass 混入
沒有專門用於字體排印的混入,但 Bootstrap 確實使用 響應式字體大小 (RFS)。