Differences and usage of div, article, and section in HTML5

Source: Internet
Author: User

Comments: Div, section article: the basic concepts of these three labels. You probably don't know much about them. The semantics is gradually enhanced from nothing. Below is a simple web page, for your reference, I hope I can be familiar with the html5 structure. Recently I am learning html5. I just got started with html5. I feel a little uncomfortable, because some labels have changed, especially div, section article: I checked some materials and tried to use html5 and css3 to deploy the webpage. There is a simple webpage that I just laid out, for your reference, let's take a look at the concept of html5 structure.

Div

HTML Spec: "The div element has no special meaning at all ."

This tag is the most common and useful one. It does not have any semantics and is used as a hook for layout and styling or script ).

Section
HTML Spec: "The section element represents a generic section of a document or application. A section, in this context, is a thematic grouping of content, typically with a heading ."

Compared with div's Silent Meaning, section is simply a div with semantics, but never think it is so simple. Section indicates a topic. It generally has a title. When we see this, we may think that a blog article or a single comment does not mean that we can use section? Next, let's see:

"Authors are encouraged to use the article element instead of the section element when it wocould make sense to syndicate the contents of the elemen ."

When the element content is aggregated to be more explicit, use article to replace the section.

So when should the section be used? Next, let's see:

"Examples of sections wocould be chapters, the varous tabbed pages in a tabbed dialog box, or the numbered sections of a thesis. A Web site's home page cocould be split into sections for an introduction, news items, and contact information."

Typical scenarios of section applications include the Chapter of the article, the tab in the tag dialog box, or the numbered part in the paper. The home page of a website can be divided into several parts: Overview, news, and contact information. In fact, I am very interested in the information here, because I feel that section and the artilce to be introduced below are more suitable for modular applications. This topic will be discussed in a special article later, and I will skip it for the time being.

Note that W3C also warned:

"The section element is not a generic container element. when an element is needed for styling purposes or as a convenience for scripting, authors are encouraged to use the div element instead. A general rule is that the section element is appropriate only if the element's contents wocould be listed explicitly in the document's outline."

Section is not just a common container label. Div should be used when a label is used only for styling or convenient script usage. In general, when the element content explicitly appears in the document outline, section is applicable.

Article
HTML Spec: "The article element represents a self-contained composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication."

Article is a special section label. It has more explicit semantics than section. It represents an independent and complete related content block. In general, article includes the title part (usually included in the header) and sometimes footer. Although section is also a topic content, in terms of structure and content, article itself is independent and complete.

In the HTML Spec, some articles are further described. "This cocould be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content ."

When articles are embedded with articles, in principle, the content of internal articles is related to the content of outer articles. For example, in a blog post, articles containing comments submitted by users should be included in articles containing blogs.

The question is, how does one calculate "complete independent content "? The simplest way to determine the content is to check whether it is complete in the RSS feed. Check whether the content is complete and independent from the context.

Example:

Html page:

The Code is as follows:
<! DOCTYPE html>
<Html lang = "en">
<Head>
<Meta charset = "UTF-8">
<Title> html5 beginners </title>
<! -- Meta tags -->
<Meta name = "keywords" content = "">
<Meta name = "description" content = "">
<! -- Stylesheets -->
<Link rel = "stylesheet" href = "css/common.css" type = "text/css">
<Link rel = "stylesheet" href = "css/layout.css" type = "text/css">
<Link rel = "stylesheet" href = "css/reset.css" type = "text/css">
<! -- Javascript -->
<Script src = "js/jquery-1.3.2.min.js"> </script>
<! -- Conditional comments -->
<! -- [If IE]>
<Script src = "js/html5.js"> </script>
<! [Endif] -->
</Head>
<Body class = "home">
<Div id = "container">
<Header id = "page-header">
<Div id = "logo"> <a href = "/"> </a> </div>
<Nav id = "main-navigation">
<Ul>
<Li class = "current"> <a href = "#"> homepage </a> </li>
<Li style = "color: red;"> <a href = "#"> about </a> </li>
<Li> <a href = "#"> service </a> </li>
<Li> <a href = "#"> Information </a> </li>
<Li> <a href = "#"> contact </a> </li>
</Ul>
</Nav>
</Header>
<Article id = "page-content">
<Section>
<Hgroup>
<H1> This Is A HTML5 webpage. <H2> HTML5 + CSS3 webpage </Hgroup>
<P> Lorem ipsum dolor sit amet, consectetur adipiscing elitVivamus ac iaculis erat. maecenas id fermentum odio. class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. fusce sagittis porta mauris, iaculis egestas metus posuere sit amet. sed ullamcorper orci eu dolor egestas sodales. donec tempor aliquet pulvinar. sed sed turpis sapien, ac dictum sem. phasellus metus leo, gravida in imperdiet sit amet, bibendum id magna. vivamus ac nunc tortor. lorem ipsum dolor sit amet, consectetur adipiscing elit. in quis justo ligula. suspendisse sodales ultricies consequat. aenean condimentum eros mi. duis consectetur placerat vehicula. fusce vel massa erat. </p>
<H2> A demonstration of list items <Ul>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
</Ul>
<Ol>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
<Li> Lorem ipsum dolor sit amet </li>
</Ol>
</Section>
<Aside>
<H2> This is part of aside. <P> Aliquam id lorem ac tellus fringilla bibendum et at turpis. in ut auctor justo. integer ac quam sed est semper hendrerit. aenean vulputate interdum augue, sed dapibus mi ultricies convallis. curabitur a nunc nisi, ac ornare nisi. ut semper placerat accumsan. cras eu nibh lorem. sed sit amet ligula vitae orci molestie sollicitudin sit amet at odio. mauris non elit ac ipsum facilisis eleifend. maecenas eu velit sit amet neque iaculis dapibus. integer mollis est id erat dignissim blandit. quisque malesuada mattis sollicitudin. pellentesque volutpat pellentesque luctus. lorem ipsum dolor sit amet, consectetur adipiscing elit. sed cursus augue ut sem convallis ullamcorper. donec vitae magna nec lacus varius pellentesque vel nec diam. morbi sagittis, magna sit amet sollicitudin ultricies, neque orci fermentum ipsum, non cursus lectus velit at ante. donec nec neque in sem suscipit faucibus. aliquam nisi turpis, volutpat quis suscipit in, varius vitae nunc. </p>
</Aside>
</Article>
</Div>
<Footer>
& Copy; Copyright Dave Woods 2009
</Footer>
</Body>
</Html>

Css page:


The Code is as follows:
@ Charset "UTF-8 ";
/* CSS Document */
# Container {
Width: 840px;
Margin: 20px auto;
Background: # fff;
Padding: 30px;
Overflow: hidden;
}
/* --------------- Header ----------------*/
# Main-navigation {
Border-bottom: 5px solid #666;
}
# Main-navigation ul {
Overflow: hidden;
Width: 100%;
List-style: none;
Font-size: 1.6em;
}
# Main-navigation li {
Float: left;
}
# Main-navigation li {
Background: #999;
Margin: 0 5px 0 0;
Padding: 5px 30px;
Display: block;
Color: # fff;
Text-decoration: none;
}
# Main-navigation li. current {
Background: #666;
}
# Main-navigation li a: hover {
Background: #777;
}
/* -------------------------- Article ------------------------*/
Article {
Width: 100%;
Overflow: hidden;
}
Section {
Float: left;
Width: 500px;
}
/* -------------------------- Article ------------------------*/
Aside {
Float: right;
Width: 310px;
}
/* -------------------------- Article ------------------------*/
Footer {
Width: 840px;
Margin: 20px auto;
Font-size: 1.4em;
Text-align: center;
}

Summary:
Div section article, the semantics is gradually enhanced from nothing. Div does not have any semantics and is only used as a styling or scripted hook. For a topic content, section is applicable. If this content can be separated from the context, as a complete piece of independent content, article is applicable. In principle, you can also use section when you can use article. But in fact, if you use article more appropriately, do not use section. The same is true for the use of nav and aside. These two labels are also special sections. If nav and aside are more suitable, do not use them.

It is easier to differentiate between div, section, article, and other labels. It is difficult to differentiate section and article. In fact, the focus is to see if the content is separated from the whole content and can still exist as a complete and independent content, the focus here is on completeness. In fact, the content contained in a section can also be regarded as an independent part, but it can only be regarded as a part of the whole, and article is a complete whole.

Finally attached to my first html5 page source code: http://xiazai.jb51.net/201308/yuanma/demoh5_jb51.net.rar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.