主体结构元素


article 元素

代表文档或页面,应用程序中独立的,完整的,可以独自被外部引用的内容。 可以是文章,帖子,评论,或其他独立的内容 有自己的标题 可以嵌套使用

article可以看做特殊类型的section元素,比section更强调独立性

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. <style>
  9. .forecast {
  10. margin: 0;
  11. padding: 0.3rem;
  12. background-color: #eee;
  13. font: 1rem "Fira Sans", sans-serif;
  14. }
  15. .forecast > h1,
  16. .day-forecast {
  17. margin: 0.5rem;
  18. padding: 0.3rem;
  19. font-size: 1.2rem;
  20. }
  21. .day-forecast {
  22. background: right/contain content-box border-box no-repeat
  23. url("/media/examples/rain.svg") white;
  24. }
  25. .day-forecast > h2,
  26. .day-forecast > p {
  27. margin: 0.2rem;
  28. font-size: 1rem;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <article class="forecast">
  34. <h1>Weather forecast for Seattle</h1>
  35. <article class="day-forecast">
  36. <h2>03 March 2018</h2>
  37. <p>Rain.</p>
  38. </article>
  39. <article class="day-forecast">
  40. <h2>04 March 2018</h2>
  41. <p>Periods of rain.</p>
  42. </article>
  43. <article class="day-forecast">
  44. <h2>05 March 2018</h2>
  45. <p>Heavy rain.</p>
  46. </article>
  47. </article>
  48. </body>
  49. </html>

section 元素

用于对网站或应用程序中页面上的内容进行分块 section 中的内容可以单独储存到数据库中或输出到Word文档中

  1. 不要将section元素用作设置样式的页面容器,这是div元素的工作
  2. 如果article元素,aside元素或nav更符合使用条件,不要使用section元素
  3. 不要为没有标题的内容区块使用section元素

nav 元素

一个用作页面导航的链接组 可用于

  1. 传统导航栏,作用是将当前页面跳转到其他页面上去
  2. 侧边导航栏,作用同上
  3. 页内导航