[html] span \n not work

 紀錄一下之前遇到的問題,html在使用 <span> </span>時 字串內含有「\n」但顯示出來後"\n"後與\n前的字串卻是平行的,後來爬文之後,發現要在style多設定 「style="white-space: pre-line"」才行。

範例:

*字串 str = "123\n123"

1.未設定「white-space: pre-line」的<span>



hmtl:

<span>@str</span>

2.設定「white-space: pre-line」的<span>


hmtl:

<span style="white-space: pre-line">@str</span>

留言

這個網誌中的熱門文章

[Visual Studio]位於網際網路或是限制區域上 或是檔案上標有 web 字樣 所以無法處理該檔案。若希望處理這些檔案 請移除 web 字樣。

[IIS] IIS執行時,發生拒絕存取路徑 問題

[SourceTree]修改使用者帳號密碼