我正在創建一個檔案頁面,并在其中一個部分嘗試解釋 HTML 檔案的結構。在最終結果中,它沒有顯示正確的縮進。
代碼:
<p>
<code>
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Title Name</title>
</head>
<body>
<h1>This is a headline.</h1>
<p>1st paragraph.</p>
<p>Usually there's quite a lot here.</p>
</body>
</html>
</code>
</p>
我什至添加了物理壓痕,但在最終結果中仍然不明顯。
<p>
<code>
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Title Name</title>
</head>
<body>
<h1>This is a headline.</h1>
<p>1st paragraph.</p>
<p>Usually there's quite a lot here.</p>
</body>
</html>
</code>
</p>
最終結果
uj5u.com熱心網友回復:
<code>
元素的語意并不意味著空格很重要。
將其與<pre>
元素結合(而不是使用段落)。
uj5u.com熱心網友回復:
使用pre
而不是code
. 中的文本pre
“通常使用非比例或等寬字體呈現。此元素內的空白顯示為書面形式。”
uj5u.com熱心網友回復:
此屬性應該是您正在尋找的:
code {
white-space: pre-wrap;
}
uj5u.com熱心網友回復:
代碼標簽不支持空格。最簡單的解決方法是用 pre 包裝代碼。
<p>
<pre>
<code>
... your code
</code>
<pre>
</p>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/516329.html
標籤:html
下一篇:HTML到資料框