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:
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://i.imgur.com/g64f8to.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
.
Create a website header. It should consist of 2 elements:
Add a <main>
section. Inside, create two sections with second-level headers
For image use following code:
<img src="https://i.imgur.com/g64f8to.png" alt="Code Basics">
The section
area complements the main content and should not exist on its own
Make 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:
Tests are designed so that they test the solution in different ways and against different data. Often the solution works with one kind of input data but doesn't work with others. Check the «Tests» tab to figure this out, you can find hints at the error output.
It's fine. 🙆 One task in programming can be solved in many different ways. If your code passed all tests, it complies with the task conditions.
In some rare cases, the solution may be adjusted to the tests, but this can be seen immediately.
It's hard to make educational materials that will suit everyone. We do our best but there is always something to improve. If you see a material that is not clear to you, describe the problem in “Discussions”. It will be great if you'll write unclear points in the question form. Usually, we need a few days for corrections.
By the way, you can participate in courses improvement. There is a link below to the lessons course code which you can edit right in your browser.
Your exercise will be checked with these tests:
1const { test } = require('tests');
2
3test(({ query, querySelectorAll, expect }) => {
4
5 const header = query(document, 'header');
6 expect(header).to.be.visible;
7
8 const img = query(header, 'img');
9 expect(img).to.be.visible;
10
11 const nav = query(header, 'nav');
12 expect(nav).to.be.visible;
13
14 const ul = query(nav, 'ul');
15 expect(ul).to.be.visible;
16
17 const li = querySelectorAll(ul, 'li');
18 expect(li).to.be.length(2);
19
20 const main = query(document, 'main');
21 expect(main).to.be.visible;
22
23 const sections = querySelectorAll(main, 'section');
24 expect(sections).to.be.length(2);
25
26 sections.forEach((section) => {
27 const h2 = query(section, 'h2');
28 expect(h2).to.be.visible;
29 });
30});
31
Teacher's solution will be available in: