HTML: Section
Large pages contain a lot of content that is intermixed with each other. There may be a separate area inside the header with the rules of use, the main section may contain a form, some additional information, and so on. They can be highlighted using the <section> tag, whose purpose is to markup related blocks in a section.
This may sound a little confusing, but imagine a music portal page that has the following areas:
- Information about the performer
- Popular tracks by the artist
- Discography
- List of upcoming concerts
If it's a page about the artist, then all of this content will be located inside the main section, and it's worth highlighting these 4 sections as well. They're related to the overall content but are independent units within it. The layout might look like this:
<main>
<h1>Blue October</h1>
<p>American alternative rock band from Houston</p>
<section>
<h2>Popular tracks</h2>
</section>
<section>
<h2>Discography</h2>
</section>
<section>
<h2>Upcoming concerts</h2>
</section>
</main>If you "pull these sections away" from the <main> tag, they will lose their meaning, because, without the text about the performer, this information might be incomprehensible. This information is directly related to the main content and cannot exist without it.
Let's add a service order form to the example we used before. This form is for ordering the service that is presented on the page only, so the section is inside the main area and is placed in a separate <section> tag.
<header>
<img src="https://cdn6.hexlet.io/1P6tmafZTIy5.png" alt="Logo"> <!-- Site Logo -->
<nav> <!-- Menu -->
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contacts">Contacts</a></li>
</ul>
</nav>
</header>
<main>
<p>The main content of the page. This can be an article, a description of a service, data, contact information, or a form to order a service</p>
<section class="callback-form">
<h2>Place an order</h2>
<form>
<!-- Here is the service order form -->
</form>
</section>
</main>In most cases, all section areas have their own header. This is a good way to know when to add a section.
Instructions
Create a website header. It should consist of 2 elements:
- Logo
- Navigation section. It should contain a bulleted list with two elements
Add a <main> section. Inside, create two sections with second-level headers
For image use following code:
<img src="https://cdn6.hexlet.io/1P6tmafZTIy5.png" alt="Code Basics">Tips
The
sectionarea complements the main content and should not exist on its ownMake sure that each section has its own header
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
HTML: Section
Large pages contain a lot of content that is intermixed with each other. There may be a separate area inside the header with the rules of use, the main section may contain a form, some additional information, and so on. They can be highlighted using the <section> tag, whose purpose is to markup related blocks in a section.
This may sound a little confusing, but imagine a music portal page that has the following areas:
- Information about the performer
- Popular tracks by the artist
- Discography
- List of upcoming concerts
If it's a page about the artist, then all of this content will be located inside the main section, and it's worth highlighting these 4 sections as well. They're related to the overall content but are independent units within it. The layout might look like this:
<main>
<h1>Blue October</h1>
<p>American alternative rock band from Houston</p>
<section>
<h2>Popular tracks</h2>
</section>
<section>
<h2>Discography</h2>
</section>
<section>
<h2>Upcoming concerts</h2>
</section>
</main>If you "pull these sections away" from the <main> tag, they will lose their meaning, because, without the text about the performer, this information might be incomprehensible. This information is directly related to the main content and cannot exist without it.
Let's add a service order form to the example we used before. This form is for ordering the service that is presented on the page only, so the section is inside the main area and is placed in a separate <section> tag.
<header>
<img src="https://cdn6.hexlet.io/1P6tmafZTIy5.png" alt="Logo"> <!-- Site Logo -->
<nav> <!-- Menu -->
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contacts">Contacts</a></li>
</ul>
</nav>
</header>
<main>
<p>The main content of the page. This can be an article, a description of a service, data, contact information, or a form to order a service</p>
<section class="callback-form">
<h2>Place an order</h2>
<form>
<!-- Here is the service order form -->
</form>
</section>
</main>In most cases, all section areas have their own header. This is a good way to know when to add a section.
Instructions
Create a website header. It should consist of 2 elements:
- Logo
- Navigation section. It should contain a bulleted list with two elements
Add a <main> section. Inside, create two sections with second-level headers
For image use following code:
<img src="https://cdn6.hexlet.io/1P6tmafZTIy5.png" alt="Code Basics">Tips
The
sectionarea complements the main content and should not exist on its ownMake sure that each section has its own header
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Your exercise will be checked with these tests:
const { test } = require('tests');
test(({ query, querySelectorAll, expect }) => {
const header = query(document, 'header');
expect(header).to.be.visible;
const img = query(header, 'img');
expect(img).to.be.visible;
const nav = query(header, 'nav');
expect(nav).to.be.visible;
const ul = query(nav, 'ul');
expect(ul).to.be.visible;
const li = querySelectorAll(ul, 'li');
expect(li).to.be.length(2);
const main = query(document, 'main');
expect(main).to.be.visible;
const sections = querySelectorAll(main, 'section');
expect(sections).to.be.length(2);
sections.forEach((section) => {
const h2 = query(section, 'h2');
expect(h2).to.be.visible;
});
});Teacher's solution will be available in:
20:00
