CSS與HTML常見的使用誤區

來源:互聯網
上載者:User
這次給大家帶來CSS與HTML常見的使用誤區,CSS與HTML使用的注意事項有哪些,下面就是實戰案例,一起來看一下。

誤區一.多p症

<p class="nav">    <ul>       <li><a href="/home/">Home</a></li>       <li><a href="/about/">About</a></li>       <li><a href="/concact/">Concact</a></li>    </ul></p>

上述使用使用多餘的p標籤現狀,就稱為“多p症”,理應簡化成下

<ul class="nav">      <li><a href="/home/">Home</a></li>      <li><a href="/about/">About</a></li>      <li><a href="/concact/">Concact</a></li></ul>

誤區二.多類class症 注意點class可以應用於頁面任意多個元素,非常適合標識內容類型或其他相似的條目

一段新聞(新聞標題、新聞詳情內容)

<h1 class="news-head">Elastic Layout Example—View Source for the HTML and CSS</h1><p class="news-head">Lorem ipsum dolor sit amet.        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

上述類名使用news-head與news-text 就稱為"多類症"表現,不需要這麼多的類區分元素樣式

最好使用p(pision)代表部分而不是沒有語義(大多數人誤解p無語義!!!),實際上p可以將文檔劃分為幾個有意義的地區.

類名news從而識別整個新聞條目。然後可以使用層疊(cascade)樣式識別新聞標題、文本,理應修改如下

<p class="news">    <h1>Elastic Layout Example—View Source for the HTML and CSS</h1>    <p>Lorem ipsum dolor sit amet.        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></p>

span 對行內元素進行分組或標識

<h2> Andy wins an Oscar for his cameo in Iron Man</h2><p>Public and on <span class="date">Februray 22nd, 2009</span>    By <span class="author">Harry Knowles</span></p>

誤區三.id使用誤區 用於標識頁面上特定元素(比如網站導覽、頁首、頁尾)而且必須唯一; 也可以用來標識持久結構性元素(如主導航、內容地區)

/*大量的使用id,很難找到唯一名稱混亂*/#andy, #rich, #jeremy, #james-box, #sophie {    font-size: 1em;    font-weight: bold;    border: 1px solid #ccc;}/*只需一個普通類替代它*/.staff {    font-size: 1em;    font-weight: bold;    border: 1px solid #ccc;}

用於標識頁面上特定元素(比如網站導覽、頁首、頁尾)而且必須唯一; 也可以用來標識持久結構性元素(如主導航、內容地區)

相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!

推薦閱讀:

百度貼吧的3D翻牌效果

css3實現動畫單車效果

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.