Bootstrap5文字排版

本文最后更新于:2 个月前

Bootstrap 5 文字排版实际上就是文字的使用。
Bootstrap 5 默认的 font-size 为 16px, line-height 为 1.5。
默认的 font-family 为 “Helvetica Neue”, Helvetica, Arial, sans-serif。
此外,所有的 <p> 元素 margin-top: 0 、 margin-bottom: 1rem (16px)。

在Bootstrap 5 中,涉及到的内容主要是H1-H6,Display 标题类以及各种表述文字内容的标签。

标题 H1-H6

1
2
3
4
5
6
7
8
<div class="container">
<h1>h1 Bootstrap 标题</h1>
<h2>h2 Bootstrap 标题</h2>
<h3>h3 Bootstrap 标题</h3>
<h4>h4 Bootstrap 标题</h4>
<h5>h5 Bootstrap 标题</h5>
<h6>h6 Bootstrap 标题</h6>
</div>

效果图

在Bootstrap 5中也支持使用.h1 - .h6 类,来做标题,效果同上。

1
2
3
4
5
6
7
8
<div class="container">
<p class="h1">h1 Bootstrap 标题</p>
<p class="h2">h2 Bootstrap 标题</p>
<p class="h3">h3 Bootstrap 标题</p>
<p class="h4">h4 Bootstrap 标题 </p>
<p class="h5">h5 Bootstrap 标题</p>
<p class="h6">h6 Bootstrap 标题</p>
</div>

标题 Display

可以输出更大的标题,使用 .display-1 - .display-6 类,效果同上。

1
2
3
4
5
6
7
8
9
```html
<div class="container">
<h1>Display 标题</h1>
<p>Display 标题可以输出更大更粗的字体样式。</p>
<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>
</div>

效果图

功能性标签

<small>

1
2
3
4
5
6
7
8
9
10
<div class="container">
<h1>更小文本标题</h1>
<p>small 元素用于字号更小的颜色更浅的文本:</p>
<h1>h1 标题 <small>副标题</small></h1>
<h2>h2 标题 <small>副标题</small></h2>
<h3>h3 标题 <small>副标题</small></h3>
<h4>h4 标题 <small>副标题</small></h4>
<h5>h5 标题 <small>副标题</small></h5>
<h6>h6 标题 <small>副标题</small></h6>
</div>

效果图

<mark>

1
2
3
4
<div class="container">
<h1>高亮文本</h1>
<p>使用 mark 元素来 <mark>高亮</mark> 文本。</p>
</div>

效果图

<abbr>

1
2
3
4
5
<div class="container">
<h1>Abbreviations</h1>
<p>The abbr element is used to mark up an abbreviation or acronym:</p>
<p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
</div>

效果图

<blockquote>

1
2
3
4
5
6
7
8
<div class="container">
<h1>Blockquotes</h1>
<p>The blockquote element is used to present content from another source:</p>
<blockquote class="blockquote">
<p>For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.</p>
<footer class="blockquote-footer">From WWF's website</footer>
</blockquote>
</div>

效果图

<dl>

1
2
3
4
5
6
7
8
9
10
<div class="container">
<h1>Description Lists</h1>
<p>The dl element indicates a description list:</p>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
</div>

效果图

<code>

1
2
3
4
5
<div class="container">
<h1>代码片段</h1>
<p>可以将一些代码元素放到 code 元素里面:</p>
<p>以下 HTML 元素: <code>span</code>, <code>section</code>, 和 <code>div</code> 用于定义部分文档内容。</p>
</div>

效果图

<kbd>

1
2
3
4
5
<div class="container">
<h1>Keyboard Inputs</h1>
<p>To indicate input that is typically entered via the keyboard, use the kbd element:</p>
<p>Use <kbd>ctrl + p</kbd> to open the Print dialog box.</p>
</div>

效果图

<pre>

1
2
3
4
5
6
7
8
9
10
11
<div class="container">
<h1>Multiple Code Lines</h1>
<p>For multiple lines of code, use the pre element:</p>
<pre>
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both spaces and
line breaks.
</pre>
</div>

效果图

更多排版类

类名 描述 效果
lead 让段落更突出
small 指定更小文本 (为父元素的 85% )
text-start 左对齐
text-center 居中
text-end 右对齐
text-justify 设定文本对齐,段落中超出屏幕部分文字自动换行
text-nowrap 段落中超出屏幕部分不换行
text-lowercase 设定文本小写
text-uppercase 设定文本大写
text-capitalize 设定单词首字母大写
initialism 显示在 <abbr> 元素中的文本以小号字体展示,且可以将小写字母转换为大写字母
list-unstyled 移除默认的列表样式,列表项中左对齐 ( <ul> 和 ```
    `` 中)。 这个类仅适用于直接子列表项 (如果需要移除嵌套的列表项,你需要在嵌套的列表中使用该样式)
list-inline 将所有列表项放置同一行