官方地址
https://getbootstrap.com/docs/4.4/content/code/
其余文档地址
- 菜鸟教程
- bs4.vx.link
code
<code></code>
在 里编写行内代码,请务必转义HTML的尖括号
<div class="container">
<h1>代码片段</h1>
<p>可以将一些代码元素放到 code 元素里面:</p>
<p>以下 HTML 元素: <code>span</code>, <code><section></code>, 和 <code>div</code> 用于定义部分文档内容。</p>
</div>
kbd
<kbd></kbd>
你可以使用 <kbd>
来标记键盘上的按钮,这看起来很生动
<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>
var
<var></var>
使用var
标记变量。
<div class="container">
<h1>变量</h1>
<p>
<var>y</var> = <var>m</var><var>x</var> + <var>b</var>
</p>
</div>
sample
<samp></samp>
使用 samp
标签来展示可能的输出结果
<div class="container">
<h1>sample用来展示程序的输出</h1>
<p>
<samp>This text is meant to be treated as sample output from a computer program.</samp>
</p>
</div>
pre
<pre></pre>
在pre
里编写多行代码。
再次确保在代码中转义任何尖括号以进行正确渲染。
你可以选择添加.pre-scrollable
类,它将设置最大高度为340px并提供y轴滚动条。
<div class="container">
<h1>Multiple Code Lines</h1>
<p>For multiple lines of code, use the pre element:</p>
<pre class="pre-scrollable">
在 <code><pre></code> 里编写多行代码。 再次确保在代码中转义任何尖括号以进行正确渲染。
你可以选择添加 .pre-scrollable 类,它将设置最大高度为340px并提供y轴滚动条。
</pre>
</div>
整体代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no"/>
<title>05代码</title>
<!--<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">-->
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<pre class="pre-scrollable">
code
kbd
var
samp
pre
</pre>
<div class="container">
<h1>代码片段</h1>
<p>可以将一些代码元素放到 code 元素里面:</p>
<p>以下 HTML 元素: <code>span</code>, <code>section</code>, 和 <code>div</code> 用于定义部分文档内容。</p>
</div>
<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>
<div class="container">
<h1>变量</h1>
<p>
<var>y</var> = <var>m</var><var>x</var> + <var>b</var>
</p>
</div>
<div class="container">
<h1>sample用来展示程序的输出</h1>
<p>
<samp>This text is meant to be treated as sample output from a computer program.</samp>
</p>
</div>
<div class="container">
<h1>Multiple Code Lines</h1>
<p>For multiple lines of code, use the pre element:</p>
<pre class="pre-scrollable">
在 <code><pre></code> 里编写多行代码。 再次确保在代码中转义任何尖括号以进行正确渲染。
你可以选择添加 .pre-scrollable 类,它将设置最大高度为340px并提供y轴滚动条。
</pre>
</div>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>