タイポグラフィ
グローバル設定、見出し、本文、リストなどを含む、Bootstrapのタイポグラフィのドキュメントと例。
グローバル設定
Bootstrapは、基本的なグローバル表示、タイポグラフィ、およびリンクスタイルを設定します。より詳細な制御が必要な場合は、テキストユーティリティクラスを確認してください。
- 各OSとデバイスに最適な
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
で定義されています。 $font-size-base
はrem
単位で設定してください。
見出し
すべての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>
関連するHTML要素を使用できない場合に、見出しのフォントスタイルを一致させたい場合は、.h1
から.h6
までのクラスも使用できます。
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>
ディスプレイ見出しは、$display-font-sizes
Sassマップと2つの変数、$display-font-weight
と$display-line-height
によって設定されます。
ディスプレイ見出しは、2つの変数、$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要素のスタイル設定。
markタグを使用してテキストを強調表示できます。
このテキスト行は、削除されたテキストとして扱われます。
このテキスト行は、もはや正確ではないものとして扱われます。
このテキスト行は、ドキュメントへの追加として扱われます。
このテキスト行は、下線が引かれた状態でレンダリングされます。
このテキスト行は、細かい活字として扱われます。
この行は、太字のテキストとしてレンダリングされます。
この行は、斜体のテキストとしてレンダリングされます。
<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>
ブロック引用
ドキュメント内の別のソースからのコンテンツブロックを引用する場合。 引用符として任意のHTMLを<blockquote class="blockquote">
で囲みます。
blockquote要素に含まれる、よく知られた引用。
<blockquote class="blockquote">
<p>A well-known quote, contained in a blockquote element.</p>
</blockquote>
出典の明記
HTMLの仕様では、blockquoteの属性は<blockquote>
の外側に配置する必要があります。属性を提供する場合は、<blockquote>
を<figure>
で囲み、<figcaption>
または.blockquote-footer
クラスを持つブロックレベル要素(例:<p>
)を使用します。ソース著作物の名前は<cite>
で囲んでください。
blockquote要素に含まれる、よく知られた引用。
<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>
blockquote要素に含まれる、よく知られた引用。
<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>
インライン
2つのクラス、.list-inline
と.list-inline-item
の組み合わせを使用して、リストの箇条書きを削除し、軽いmargin
を適用します。
- これはリスト項目です。
- もう1つです。
- しかし、これらはインラインで表示されます。
<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>
定義リストの配置
グリッドシステムの定義済みクラス(またはセマンティックmixin)を使用して、用語と説明を水平方向に整列します。長い用語の場合は、必要に応じて.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 mixin
タイポグラフィ専用のmixinはありませんが、Bootstrapはレスポンシブフォントサイズ(RFS)を使用しています。