【问题标题】:Which one comes first, main tag or section tag?哪个先出现,主要标签还是部分标签?
【发布时间】:2018-11-15 04:53:18
【问题描述】:

<section> 标记应该在<main> 标记内还是相反?可以制作包含许多<section> 标签作为其后代的<main> 标签吗?示例:

<body>
  <main>
    <section></section>
    <section></section>  
    <section></section>
    <section></section>
  </main>
</body>

【问题讨论】:

标签: html


【解决方案1】:

我不同意 divya jyothi。在该示例中,“部分”用于构建页面的各个块,而它应该用于将文章中的内容划分为有意义的块。 显然,这取决于个人喜好,但这是我向客户推荐的:

<html>
    <head></head>

    <body>
        <header>
            <nav>[main menu]</nav>
        </header>

        <main>
            <article>

                <h1></h1>
                <p>Intro</p>

                <section>
                    <h2>Header for theme of first section</h2>
                    <p>Text</p>
                </section>
                <section>
                    <h2>Header for theme of second section</h2>
                    <p>Text</p>
                </section>
                <section>
                    <h2>Header for theme of third section</h2>
                    <p>Text</p>
                </section>

                <aside>
                    Comments directly related to the article
                </aside>
                <aside>
                    Other articles similar to the main article
                </aside>

            </article>

            <aside>
                Block of content not directly related to article ie form to sign up
            </aside>



        </main>
        <nav>[right column menu]</nav>

        <footer>
            <nav>[bottom menu]</nav>
        </footer>       
    </body>
</html>

变化显然是无限的,但我认为这是一个很好的基本模板。在此处阅读更多信息https://www.semrush.com/blog/semantic-html5-guide/,您可以在此处可视化您的语义 HTML5 结构https://sitegardien.com/html5viewer/semantichtml5viewer.php

【讨论】:

  • 并且你不应该将 ID 或类放在语义标签中,除非它的唯一目的是作为锚
  • 大概你的标题中的[主菜单]是顶部导航栏菜单,就像你在主菜单之后有一个[右栏菜单]一样,你也可以在主菜单之前有一个[左栏菜单]。另请注意,页眉、页脚不一定每个文档一个,可以有多个,比如每个部分一个,甚至每个文章一个。
  • 好吧,如果左列或右列是导航菜单,那么它们应该在
    之外,但如果它们包含指向与页面主要内容相关的文章的链接,我会说
    中的
  • 谢谢,我刚刚接受了你的回答,你是对的!
【解决方案2】:

&lt;main&gt; 元素应该包含我们网页的主要内容,并且内容应该对单个页面是唯一的,并且不应出现在网站的其他地方。

&lt;section&gt;元素用于表示一组相关内容。

您可以在&lt;main&gt; 标签内使用&lt;section&gt;

HTML语义标签的理想结构是

<main id="wrapper">
   <section id="content">
      <article id="post">
                    <header>
                        <h1>HTML Semantic tags</h1>
                        <p>Correctly Use Semantic HTML5 <article>, <main> and <section> 
                        Tags</p>
                    </header>
     <footer>
           <p>Correctly Use Semantic HTML5 <article>, <main> and <section> 
                        Tags</p>
     </footer>

                    <section id="comments">

                        <article>
                            <p>This is my all important comment, please don't delete it. 
                            </p>
                        </article>

                    </section>

                </article>

            </section>

            <aside>
            </aside>

        </main>

【讨论】:

  • 根据 W3Schools 的说法,这是不准确的。 “
    元素内的内容对于文档应该是唯一的。它不应包含在文档中重复的任何内容,例如侧边栏、导航链接、版权信息、网站徽标和搜索表单。”
【解决方案3】:

好的,基本上,你可以在这里使用你的逻辑。部分是您网站的一部分。例如,页脚将是一个部分。此外,页面的任何部分都是一个部分。现在您可以将这些部分包装在其他任何内容中......无论是&lt;body&gt;标签还是

<body>
  <main>
    <div class wrapper>
      <section>

这么说简单,主要先于部分:)

【讨论】:

    猜你喜欢
    • 2012-11-05
    • 2016-07-07
    • 2017-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 1970-01-01
    • 2014-06-03
    相关资源
    最近更新 更多