HTML Nav标记未按预期工作

时间:2017-08-05 18:33:43

标签: html html5 nav

我正在使用html,想要建立自己的网站。我试图获取页面左侧最常用网站的链接,因为我相信导航的功能。此外,我似乎无法将我的文本正文放在页面的中心,也不能显示标题。这是我的代码;

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My first webpage</title>
  </head>
    <header>Ian Witkowski</header>
    <nav>
    <h1>My Favorite Websites</h1>
    <ul>
      <li><a href=http://www.youtube.com/>YouTube</a>
      <li><a href=http://www.google.com/>Google</a>
      <li><a href=http://www.reddit.com/>Reddit</a>
    </ul>
    </nav>
  <body>
    <article>
    <h1>The Penultimate Website</h1>
    <h2>The Official Homepage of Ian Witkowski</h2>
    <p>Thank you for visiting my webpage!</p>
    <dl>
      <dt><h3>Ian Witkowski</h3></dt>
      <dd>A cool dude</dd>
    </dl>
    <p>

    Reasons Ian is cool;</p>
    <ul>
      <li>He is nice</li>
      <li>He rides bikes</li>
      <li>He likes computers</li>
      <li>He can code his own website</li>
    </ul>
    <p>Here is a link for my arbitrary code test page;</p>
    <ul>
      <li><a href="secondpage.htm" target="_blank">Ian2</a></li>
    </ul>
  </article>    
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

nav什么也没做。它只是一个像div这样的标签。但作为HTML5规范的一部分,他们添加了section, nav, footer, header标记以简化页面描述。

没有css,它只是一个没有任何关于设计的特殊行为的标签

第二件事,你的HTML有错误。除了头部之外的所有东西都应该在体内(包括导航)

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My first webpage</title>
  </head>
  <body>
    <header>Ian Witkowski</header>
    <nav>
    <h1>My Favorite Websites</h1>
    <ul>
      <li><a href=http://www.youtube.com/>YouTube</a>
      <li><a href=http://www.google.com/>Google</a>
      <li><a href=http://www.reddit.com/>Reddit</a>
    </ul>
    </nav>
    <article>
    <h1>The Penultimate Website</h1>
    <h2>The Official Homepage of Ian Witkowski</h2>
    <p>Thank you for visiting my webpage!</p>
    <dl>
      <dt><h3>Ian Witkowski</h3></dt>
      <dd>A cool dude</dd>
    </dl>
    <p>

    Reasons Ian is cool;</p>
    <ul>
      <li>He is nice</li>
      <li>He rides bikes</li>
      <li>He likes computers</li>
      <li>He can code his own website</li>
    </ul>
    <p>Here is a link for my arbitrary code test page;</p>
    <ul>
      <li><a href="secondpage.htm" target="_blank">Ian2</a></li>
    </ul>
  </article>    
  </body>
</html>