原文網址:HTML--pre標簽的作用-CSDN博客
簡介
本文介紹HTML里pre標簽的作用。
<pre> 元素表示預定義格式文本。里邊的文本會保留原格式,以等寬字體的形式展現出來,文本中的空白符(比如空格和換行符)都會顯示出來。(緊跟在 <pre> 開始標簽后的換行符會被省略)。
而在其他標簽里,會忽略空格和換行,導致內容和原格式不一致。
示例
例1:使用pre
<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 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>
結果(左側的縮進和最后的換行都沒了)