HTML白色代碼怎么寫呢?其實很簡單,我們只需要使用pre標簽來包含代碼,并設置好樣式即可。以下是具體步驟:
首先,我們需要創建一個HTML文檔,并在其中添加需要展示的代碼。例如,我們要展示一個簡單的HTML頁面結構,可以這樣寫:
<!DOCTYPE html> <html> <head> <title>My Website</title> </head> <body> <header> <h1>Welcome to my website!</h1> </header> <nav> <ul> <li><a href="#">Menu 1</a></li> <li><a href="#">Menu 2</a></li> <li><a href="#">Menu 3</a></li> </ul> </nav> <main> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor libero vel sapien fermentum congue. Sed accumsan porta metus, non tempus sapien posuere non.</p> </main> <footer> <p>Copyright © 2020 My Website</p> </footer> </body> </html>代碼寫好后,我們需要添加pre標簽將其包裹起來,如下所示:
<pre> <!DOCTYPE html> <html> <head> <title>My Website</title> </head> <body> <header> <h1>Welcome to my website!</h1> </header> <nav> <ul> <li><a href="#">Menu 1</a></li> <li><a href="#">Menu 2</a></li> <li><a href="#">Menu 3</a></li> </ul> </nav> <main> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed auctor libero vel sapien fermentum congue. Sed accumsan porta metus, non tempus sapien posuere non.</p> </main> <footer> <p>Copyright © 2020 My Website</p> </footer> </body> </html> </pre>
最后,我們只需要設置pre標簽的CSS樣式即可。通常,我們會將pre標簽的背景色設為白色,代碼字體設為等寬字體,如下所示: pre { background-color: #fff; font-family: 'Courier New', Courier, monospace; } 這樣,我們就成功展示了一段白色HTML代碼!