• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

learn-co-students/html5-semantic-containers-lab-online-web-sp-000

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

learn-co-students/html5-semantic-containers-lab-online-web-sp-000

开源软件地址:

https://github.com/learn-co-students/html5-semantic-containers-lab-online-web-sp-000

开源编程语言:

Ruby 58.5%

开源软件介绍:

HTML5 Semantic Elements Lab

Problem Statement

In HTML5, there are many new tags that help us describe what kind of content exists within a specific tag. These are referred to as semantic elements. In this lesson, we will be introducing some of the most useful tags.

Objectives

  1. Introduce common semantic tags in HTML
  2. Explore their use by applying them to existing content

Non-Semantic Elements

Before we dive into semantic elements, lets see some examples of non-semantic elements. Two of the most commonly used HTML tags are span and div. Neither tag has automatic styling. The only difference between them: content wrapped with the span tag will display without line breaks, whereas content wrapped with div will:

<span>This content will share the same line...</span><span>...as this content</span>

<div>
  This message will appear on a new line
</div>

These tags certainly have their uses, and developers can sometimes favor them because of the lack of styling. However, they don't give any indication as to what type of content they're wrapping. They are just dividers of the content.

Semantic Elements

Many semantic elements also lack automatic styling, and act very similar to the div tag. What they provide, instead, is an explanation of what they wrap.

<header> and <footer> Tags

The first two semantic tags to discuss are the header and footer tags. The purpose of these may seem obvious to those who have used document editors like Microsoft Word. The header tag is used to wrap all content we would want to contain within the top, (header), portion of a page. The footer is for everything at the foot, (bottom), of a page:

<header>
  <!-- Headers often contain company logos -->
</header>

<!-- All the main content of a web page goes in between -->

<footer>
  <!-- Footers often contain resources, privacy policy links, and copyright information -->
</footer>

Commonly, a website with many different pages will have the same header and footer content on each page...the only content that changes is what is in between.

<nav> Tags

Typically, inside or just below the header section of a page are navigation links to help users access different parts of a website. For this block of links, we can use the nav tag. Wrapping nav around links helps describe those links as the page navigation itself:

<nav>
  <a href="about.html">About</a>
  <a href="contact.html">Contact</a>
</nav>

A reader glancing over an HTML page can quickly see what these links are meant for. The nav tag is not meant for all links, just those typically used for site navigation.

<main> Tag

The main tag specifies the main content of a web page. This would typically be everything in between the header and footer areas, and may contain many nested tags:

<header></header>
<nav></nav>

<main>
  <!-- All the main content of a web page goes here -->
</main>

<footer></footer>

With these few tags, common content within a web page can be separated in a way that is easy to understand.

<section> Tag

Within the main tag, we can continue to breakdown content into specific, meaningful sections. One way we can do this is to use the...well...section tag.

<section>
  <p>Lorem ipsum dolor sit amet...</p>
  <p>Lorem ipsum dolor sit amet...</p>
</section>

The section tag can be used to define specific portions of a web page. A page may have multiple boxes of content within a larger container like main. For each box, we can use a section tag to separate the content.

<article> and <aside> Tags

The section tag is more informative than the div tag, but it still may not be as specific as we need. For particular parts of a web page, we have semantic options like article and aside. The article tag is for containing written content such as a news story or blog post. The aside tag is for containing content that may be related to other content, but is better kept separated.

<article>
  <h1>First Human Digitizes Brain</h1>
  <p>In 2018, Chrome Boi became the first human to digitize their brain. They now live in the Internet.</p>
</article>

<aside>
  <h4>Once human, now digital</h4>
  <p>A quick visit to https://en.wikipedia.org/wiki/Draft:Chrome_Boi will show you the ascended individual</p>
</aside>

<figure> and <figcaption> Tags

Along with section, article, and aside, we also have some tags specific for containing image and media content. The <figure> tag wraps self-contained media content. For instance, a blog post could have an accompanying image to support the content.

The figure tag also comes with a companion for providing captions, the figcaption tag. Since figure is used for media, the figcaption tag can be used to add an additional message about that media or its source.

<section>
  
  <article>
    Lorem ipsum dolor sit amet...
  </article>
  
  <figure>
    <img src="images/intro-pic.jpg"  alt="An exceptional living room." title="Welcome to Exceptional Living Rooms">
    <figcaption>"An Exceptional Living Room" by Leonardo DaVinci, photograph</figcaption>
  </figure>
  
</section>

Here, we've wrapped an image in the <figure> tag, and included a <figcaption> providing the title and creator of the image.

Practice with Semantic Elements

Let's practice what we've discussed. In index.html, we have a web page with some example content for a real estate agency. However, most of the HTML tags within the body are non-semantic div and span tags.

Your task is to read through the provided comments and add in the appropriate semantic tags. Run learn to test your work and use the provided error messaging to work through the tests. When finished, run learn submit.

Note: there are a few semantic tags in index.html not explicitly discussed in this readme. Use the comments to figure out what tag you will have to use.

Make sure that for every div and span you replace, that you also replace the corresponding closing tag!

You can view index.html in the browser by running httpserver or opening the file in a separate browser tab. It is worth noting, though, that the layout of the page won't change as you add semantic tags. We are not changing the styling or structure, but the description of the content contained on the page.

Conclusion

Using semantic tags serves multiple functions. They provide a greater readability for yourself or anyone else who may edit an HTML document in the future. They also make it easier to style your pages. As a bonus, they help search engines identify and categorize content on websites.

When using Cascading Style Sheets, we can easily set up styling for just the specific semantic elements. These tags are more natural to write and faster to understand than div and span tags.

There are more semantic tags to explore, some of which you've already used! Tags such as form and table are semantic as well, as they describe the contents within.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap