亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

HTML 中的代碼格式縮進出現在文檔中

HTML 中的代碼格式縮進出現在文檔中

繁花如伊 2023-08-21 19:25:32
這是我從 Anki(抽認卡創建程序)復制并粘貼的 HTML 代碼。該代碼運行良好。(背景:抽認卡是一道編程題)<meta content="width=window-width, initial-scale=1.0" name="viewport">瀏覽器上渲染的代碼:顯然,該代碼以當前格式不可讀。為了解決這個問題,我添加了適當的縮進。<meta content="width=window-width, initial-scale=1.0" name="viewport">What does this code do?<div>  <div background-attachment:="" background-clip:="" background-image:="" background-origin:="" background-position:="" background-repeat:="" background-size:="" class="highlight" initial;="" initial;"="">    <pre style="line-height: 25px;">      <table class="highlighttable" style="font-family: Arial;">        <tbody>          <tr>            <td>              <div 10px"="" class="linenodiv" padding-right:="">                <pre style="line-height: 125%">1</pre>              </div>            </td>            <td class="code">              <div class="highlight">                <pre style="line-height: 125%">&lt;<span style="color: #008000; font-weight: bold">meta</span> <                  span style="color: #7D9029">http-equiv</span>                  <span style="color: #666666">=</span>                  <span style="color: #BA2121">"X-UA-Compatible"</span>                  <span style="color: #7D9029">content</span>                  <span style="color: #666666">=</span>                  <span style="color: #BA2121">"IE=edge"</span>&gt;                </pre>              </div>            </td>          </tr>        </tbody>      </table>    </pre>  </div>  <div>    <center>      <br>    </center>  </div></div>奇怪的是:上面的縮進現在出現在 HTML 文檔中。這不應該發生,對嗎?我認為 HTML 中的換行符對用戶不可見?
查看完整描述

1 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

那是因為whitespaceis pre(由瀏覽器保留)。這樣做的目的是為了讓您可以縮進代碼。通常,當您想要在 HTML 中呈現代碼時,您可以取消縮進:


? ? ? ? ? ? <td class="code">

? ? ? ? ? ? ? <div class="highlight">

? ? ? ? ? ? ? ? <pre style="line-height: 125%">&lt;<span style="color: #008000; font-weight: bold">meta</span>

<span style="color: #7D9029">http-equiv</span>

<span style="color: #666666">=</span>

<span style="color: #BA2121">"X-UA-Compatible"</span>

<span style="color: #7D9029">content</span>

<span style="color: #666666">=</span>

<span style="color: #BA2121">"IE=edge"</span>&gt;

? ? ? ? ? ? ? ? </pre>

? ? ? ? ? ? ? </div>

? ? ? ? ? ? </td>

請注意,您不需要在行<pre>本身上執行此操作(這就是元部分顯示您所需的縮進的原因)。


如果您要經常使用代碼片段,像?Prismjs這樣的庫將使您的生活變得更加輕松并且值得花費這些開銷(事實上,這是一個非常輕量級的庫):


<pre><code class="language-html">(... html code ...)</code></pre>


查看完整回答
反對 回復 2023-08-21
  • 1 回答
  • 0 關注
  • 128 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號