排版(Typography)
Bootstrap 排版的文件與範例,包括全域設定、標題、內文、列表等。
全域設定(Global settings)
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。
標題(Headings)
所有 HTML 標題,從 <h1> 到 <h6> 都可使用。
| 標題 | 範例 |
|---|---|
<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>
.h1 到 .h6 類別也可使用,當您想要匹配標題的字型樣式但無法使用相關的 HTML 元素時。
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> 自訂標題(Customizing headings)
使用包含的通用類別來重現 Bootstrap 3 中的小型次要標題文字。
Fancy display heading With faded secondary text
<h3>
Fancy display heading
<small class="text-body-secondary">With faded secondary text</small>
</h3> 展示標題(Display headings)
傳統的標題元素設計為在頁面內容的主體中效果最佳。當您需要一個脫穎而出的標題時,請考慮使用展示標題——一種更大、稍微更有個性的標題樣式。
<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-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
透過加入 .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> 行內文字元素(Inline text elements)
常見行內 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> 主要用於語音、技術術語等。
文字通用類別(Text utilities)
使用我們的文字通用類別和顏色通用類別來改變文字對齊、轉換、樣式、粗細、行高、裝飾和顏色。
縮寫(Abbreviations)
HTML <abbr> 元素的樣式化實作,用於縮寫和首字母縮略詞,在懸停時顯示展開版本。縮寫有預設的底線,並獲得幫助游標,以便在懸停時和對輔助技術使用者提供額外的上下文。
為縮寫加入 .initialism 以獲得稍小的字型大小。
attr
HTML
<p><abbr title="attribute">attr</abbr></p>
<p><abbr title="HyperText Markup Language" class="initialism">HTML</abbr></p> 引用區塊(Blockquotes)
用於在文件中引用來自其他來源的內容區塊。將 <blockquote class="blockquote"> 包裹在任何 HTML 周圍作為引用。
A well-known quote, contained in a blockquote element.
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote> 標註來源(Naming a source)
HTML 規範要求引用區塊的署名應放置在 <blockquote> 之外。在提供署名時,將您的 <blockquote> 包裹在 <figure> 中,並使用 <figcaption> 或帶有 .blockquote-footer 類別的區塊級元素(例如 <p>)。請確保也將來源作品的名稱包裹在 <cite> 中。
A well-known quote, contained in a blockquote element.
<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> 對齊(Alignment)
根據需要使用文字通用類別來更改引用區塊的對齊方式。
A well-known quote, contained in a blockquote element.
<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> A well-known quote, contained in a blockquote element.
<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> 列表(Lists)
無樣式(Unstyled)
移除列表項目(僅直接子元素)的預設 list-style 和左邊距。這只適用於直接子列表項目,意味著您需要為任何巢狀列表也新增該類別。
- 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> 行內(Inline)
使用兩個類別的組合 .list-inline 和 .list-inline-item 來移除列表的項目符號並套用一些輕量的 margin。
- 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> 描述列表對齊(Description list alignment)
使用我們格線系統的預定義類別(或語義化 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> 響應式字型大小(Responsive font sizes)
在 Bootstrap 5 中,我們預設啟用了響應式字型大小,讓文字可以在裝置和視窗大小之間更自然地縮放。查看 RFS 頁面以了解其運作方式。
CSS
Sass 變數(Sass variables)
標題有一些專用的變數用於大小和間距。
$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;
// scss-docs-start vr-variables
$vr-border-width: var(--#{$prefix}border-width);
// scss-docs-end vr-variables
$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 mixins
排版沒有專用的 mixins,但 Bootstrap 確實使用了響應式字型大小(RFS)。