简介
本文介绍HTML里pre标签的作用。
<pre> 元素表示预定义格式文本。里边的文本会保留原格式,以等宽字体的形式展现出来,文本中的空白符(比如空格和换行符)都会显示出来。(紧跟在 <pre> 开始标签后的换行符会被省略)。
而在其他标签里,会忽略空格和换行,导致内容和原格式不一致。
示例
例1:使用pre
html
<html xml:lang="cn" lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="keywords" content="anchor,fixed navigation hide anchor">
<title>测试</title>
<style>
</style>
</head>
<body>
<pre>
这是第一行
这是第二行
</pre>
</body>
</html>
结果(所有的缩进和换行等都跟原来一样)

例2:使用其他标签
html
<html xml:lang="cn" lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="keywords" content="anchor,fixed navigation hide anchor">
<title>测试</title>
<style>
</style>
</head>
<body>
<div>
这是第一行
这是第二行
</div>
</body>
</html>
结果(左侧的缩进和最后的换行都没了)
