老外寫的一篇文章:what beautiful html code looks like 如何寫出漂亮的html代碼 感覺寫的非常的不錯,轉載過來,與大家分享一下:
ps:原文地址:http://css-tricks.com/what-beautiful-html-code-looks-like/
1.doctype properly declared
別忘記頭部的聲明,它會告訴瀏覽器如何渲染你的html。
2.tidy head section
設置title,字符集.將css和js外鏈(包括一個打印用的css)。
3.body ided
給body一個id。這里作者提到的原因是,為多頁面的中容器選擇提供便利。比如通過給page1和page2中body設置不同的id,就可以通過#page1 h2和#page2 h2來設置兩種不同的效果,我感覺這個到是要看情況和具體架構再具體使用。
4.semantically clean menu
編寫符合語意的菜單代碼。<div id="menu">
<ul>
<li><a href="index.php">home</a></li>
<li><a href="about.php">about</a></li>
<li><a href="contact.php">contact</a></li>
</ul>
</div>
ps:我個人覺得這樣寫代碼應該更簡單一點吧:
<ul id="menu">
<li><a href="index.php">home</a></li>
<li><a href="about.php">about</a></li>
<li><a href="contact.php">contact</a></li>
</ul>
5.main div for all page content
要有一個主體div包含所有的內容。方便固定主體的寬度,邊距等等。
6.important content first
先寫主要內容,再寫次要內容.如果你的導航或者側邊欄不是很重要,最好將他們寫在最后。
7.common content included
將導航,頁尾等公用的部分用動態調用的方式引入,比如php的include。
8.code is tabbed into sections
縮進代碼
9.proper ending tags
注意結束標簽
10.hierarchy of header tags
在合適的地方使用標題標簽,如<h1>~<h6>,來劃分段落。
11.content, content, content
使用合適的標簽,和標志代碼,用© 表示©,不要使用</br>
12.no styling!
不要把樣式寫在標簽上,html只是用來表示結構。表現還是交給css吧。
新聞熱點
疑難解答