Lesson 04 · 12 steps
The point where separate files become a site. link.html plus two more pages and four text files: addresses that are relative and absolute, jumps inside a page and into another one, and the four states every link has.
<!-- 2) абзац за темою сайту і перехід на другу сторінку --> <p> Counter-Strike 2 — командна гра, у якій перемагає не найшвидша рука, а команда, що краще домовилася. </p> <a href="link_1.html" title="правила матчу"> друга сторінка </a>
The a tag — «anchor» — is the whole of the web in one tag: href says where to go, and the text between the tags is what you click. title adds the tooltip you met in lesson 1.
link_1.html is a relative address: «a file called that, in the same folder as this one». Move both files together and the link still works.
<html> <head> <meta charset="utf-8"> <title> CS2 UA. Друга сторінка </title> </head> <body> <!-- 3) два абзаци за темою сайту --> <p> Матч складається з раундів, а не з часу: виграє та команда, яка першою бере 13 раундів. </p> <p> Після 12 раундів команди міняються сторонами, тому грати доводиться і за терористів, і за контртерористів. </p> <!-- 3) перехід назад на першу сторінку --> <a href="link.html" title="повернутися на головну"> перша сторінка </a> </body> </html>
Nothing new here — the same tag pointing the other way. Worth noticing that a site is just this: files that know each other's names.
<!-- 4) відносне та абсолютне посилання на текстові файли --> <h3> Файли </h3> <a href="text1.txt"> Відносне посилання на файл у папці поточного файлу </a> <br> <a href="file:///D:/Korchagin/text2.txt"> Абсолютне посилання на файл у папці D </a> <br>
A relative address is measured from the page doing the linking. An absolute one starts from the very top — a disk, or a site — and carries the whole path with it.
The absolute link here points at D:/Korchagin/text2.txt, which only exists on one Windows machine. In the preview below it is a dead link, and that is the honest demonstration: an absolute address is the price you pay for a fixed place in the world.
On the web the two look like /studies/html/ (absolute, from the site root) and files/main.html (relative). Linking to a file on somebody's disk is simply never done — which is why the assignment can only show it with a path that is going to be broken for everyone else.
<!-- 5) посилання всередині цієї ж сторінки --> <h2> Клацніть посилання, щоб перейти до відповідного розділу </h2> <p><em><a href="#economy"> Економіка раунду </a></em></p> <p><em><a href="#roles"> Ролі в команді </a></em></p> <h2><a name="economy" id="economy"> Економіка раунду </a></h2> <p> Гроші в Counter-Strike — така сама зброя, як автомат: команда, яка вміє рахувати, виграє раунди ще до пострілу. Перемога дає 3250 доларів, поразка — менше, і через це з'являються еко-раунди. </p> <h2><a name="roles" id="roles"> Ролі в команді </a></h2> <p> П'ятеро гравців рідко роблять одне й те саме: хтось заходить першим, хтось тримає снайперську лінію, хтось вирішує за всіх. Саме розподіл ролей відрізняє команду від п'ятьох окремих людей. </p>
A link whose address begins with # stays on the page and jumps to the spot carrying that name. The target is marked with id — here on the headings.
This is how a long page gets a table of contents, and it is also what makes kogiant.com/studies/html#lesson-4-style addresses possible.
<a name="..."> is the old way of marking the target; today any tag can be a target as long as it has an id. Both are in the code above because the assignment asks for the old spelling.
<!-- 6) посилання на окремі абзаци іншого файлу --> <h2> Клацніть посилання, щоб перейти до розділу іншої сторінки </h2> <p><em><a href="link_2.html#ak"> Про AK-47 </a></em></p> <p><em><a href="link_2.html#awp"> Про AWP </a></em></p>
<!-- 6) мітки, на які веде посилання з файлу link.html --> <h2><a name="ak" id="ak"> AK-47 </a></h2> <p> Автомат терористів за 2700 доларів. Вбиває з одного влучання в голову навіть крізь шолом, але сильно підкидає ствол угору. </p> <h2><a name="awp" id="awp"> AWP </a></h2> <p> Снайперська гвинтівка за 4750 доларів. Одне влучання в тулуб — і раунд уже інший. Через ціну її втрата болить навіть більше за смерть. </p>
Combine the two: file name, then #, then the name of the spot. The browser opens the other page and scrolls straight to it.
<!-- 9) посилання на текстові файли та на графічний файл --> <h3> Ще файли </h3> Це <a href="4_2.txt"> відносна адресація файлу </a> 4_2.txt <br> Це <a href="file:///D:/Korchagin/4_1.txt"> абсолютна адресація файлу </a> 4_1.txt <br> Це <a href="images/navi.jpg"> графічний файл </a> navi.jpg <br> Це <a href="https://www.hltv.org" target="_blank"> сайт із результатами матчів </a> — відкриється в новій вкладці <br>
A link does not have to lead to a page. Point it at a text file and the browser shows the text; point it at a picture and it shows the picture; point it at something it cannot display and it offers to download.
target="_blank" opens the address in a new tab and leaves your page where it was.
target="_blank" is usually written with rel="noopener" beside it. Without that, the page you opened gets a handle on yours and can quietly replace it — a trick that was used for phishing.
<!-- 10) псевдокласи оформлення посилань -->
<style type="text/css">
a:link {color:#1a5fb4;text-decoration:none;font-size:14pt}
a:visited {color:grey}
a:hover {color:#2a8a2a;text-decoration:underline;font-size:15pt}
a:active {background:#f0a500}
</style>
<!-- 10) чотири посилання на сайти схожої тематики --> <h1> Сайти </h1> <a href="https://www.counter-strike.net/"> офіційний сайт Counter-Strike 2 </a> <br> <a href="https://www.hltv.org/"> HLTV — результати матчів і рейтинги </a> <br> <a href="https://navi.gg/"> Natus Vincere </a> <br> <a href="https://www.esl.com/"> ESL — організатор турнірів </a> <br>
A link lives in four states and CSS can reach each one: a:link — untouched, a:visited — already been there, a:hover — the mouse is on it, a:active — the moment of the click.
Hover over the links in the preview: they turn green and grow, because a:hover says so.
Growing the font on hover is a bad habit — the text under the cursor jumps and the line reflows. The usual choices are a colour change or an underline, and :focus-visible is added so the keyboard sees the same thing the mouse does.
<!-- 11) сім горизонтальних ліній різного вигляду --> <h3> Горизонтальні лінії </h3> <p> Лінія вирівняна по лівому краю </p> <hr align="left" width="300" color="DarkGreen"> <p> по правому краю </p> <hr align="right" width="25%" color="Cyan"> <p> по центру </p> <hr align="center" width="100" color="Peru"> <p> лінія з тінню </p> <hr size="10" width="75%" color="red"> <p> лінія без тіні </p> <hr noshade size="10" width="75%" color="red"> <p> лінія товщиною 5 пікселів та шириною 50% </p> <hr noshade size="5" width="50%" color="Aquamarine"> <p> лінія товщиною 20 пікселів та шириною 200 пікселів </p> <hr noshade size="20" width="200" color="SkyBlue">
hr is a line across the page, and the attributes set its width, thickness, colour and alignment. noshade removes the carved-in-stone effect browsers used to draw by default.
Every one of those attributes is gone from HTML today: a rule is drawn with border and width in CSS, and hr survives as a mark of «the subject changes here» rather than as a drawing tool.