【问题标题】:Html Hierarchy: Whats acceptable when extending the <head>?Html 层次结构:扩展 <head> 时可以接受什么?
【发布时间】:2013-05-27 05:19:32
【问题描述】:

在创建 html 文档时,我的代码可以以任何方式工作,但其他人喜欢如何组织他们的 html 层次结构?例如,我喜欢将网站的横幅和导航栏放在&lt;head&gt;

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="style.css" />
        <script type='text/javascript' src='script.js'></script>

        <title> User's Profile'</title>

        <div id="header">
            <img src="http://svc004.bookeasy.com/images/MARGS/flourish-website-banner3.jpg" />
        </div>

        <div id="toolbar">
            <span>Username</span>
            <p>Profile</p>
            <p>Medals</p>
            <p>Account Settings</p>
            <p>logout</p>
        </div>

    </head>
    <body>

        <div id="left_nav">
            <p>Home</p>
            <p>Scout</p>
            <p>Attack</p>
            <p>Fourms</p>
            <p>Contact</p>
        </div>
    </body>
</html>

【问题讨论】:

  • 你有什么感觉...哦。 ;)
  • @alex 哈哈,很聪明

标签: html hierarchy code-organization


【解决方案1】:

您不应该在 head 中添加任何要显示为 en 元素的内容,因为它不是正确的元素。

它可能会起作用,但你永远不知道它什么时候可能不起作用(或有细微的错误)。它还会使任何必须在您之后维护此标记的人感到困惑。

【讨论】:

    【解决方案2】:

    The spec 表示&lt;head&gt; 元素必须包含:

    元数据内容的一个或多个元素,其中恰好一个是title 元素。

    再往下:

    元数据内容是设置其余内容的表示或行为的内容,或者设置文档与其他文档的关系,或者传达其他“带外”信息的内容。

    你只能把这些标签放在那里:

    • &lt;base&gt;
    • &lt;link&gt;
    • &lt;meta&gt;
    • &lt;noscript&gt;
    • &lt;script&gt;
    • &lt;style&gt;
    • &lt;title&gt;

    你这样做的方式并不好。将标题放在&lt;body&gt; 中的&lt;header&gt; 元素中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-06
      • 1970-01-01
      • 1970-01-01
      • 2016-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多