Lesson 07 · 20 steps
list.html is the longest file in the practicum: three kinds of list, three levels of nesting, pictures instead of bullets, numbers that CSS counts by itself — and a drop-down menu built from a plain list without a single line of script.
<!-- 2) маркований список --> <h2> Карти активного пулу </h2> <ul type="disc"> <li> Dust II </li> <li> Mirage </li> <li> Inferno </li> <li> Nuke </li> </ul>
ul holds the list, li is one item. The browser adds the bullets and the indent by itself — none of that is in the markup.
type="disc" is the old spelling. The shape of the marker is appearance, so CSS owns it now: list-style-type:disc, or square, or none.
<!-- 3) нумерований список --> <h2> Як проходить раунд </h2> <ol> <li> закупівля; </li> <li> вихід на точку; </li> <li> закладання бомби. </li> </ol>
Swap ul for ol and the same items get numbers. The numbers are generated, not typed — insert an item in the middle and everything below renumbers itself.
<!-- 4) багаторівневий нумерований список, три рівні -->
<h2> Зброя </h2>
<ol>
<li> Пістолети </li>
<ol>
<li> Glock-18 </li>
<li> USP-S </li>
</ol>
<li> Автомати </li>
<ol>
<li> AK-47 </li>
<ol>
<li> одиночними з далекої дистанції </li>
<li> чергами зблизька </li>
</ol>
<li> M4A1-S </li>
</ol>
<li> Снайперські гвинтівки </li>
<ol>
<li> AWP </li>
<li> SSG 08 </li>
</ol>
</ol>
Lists nest: a list inside an item is a sub-list. Three levels here, and the indentation in the code is what keeps it readable — the browser does not care, but the person editing it does.
<!-- 5) багаторівневий маркований список, два рівні -->
<h2> Гранати </h2>
<ul>
<li> Закривають огляд
<ul>
<li> димова </li>
<li> запалювальна </li>
</ul>
</li>
<li> Заважають суперникові
<ul>
<li> світлошумова </li>
<li> осколкова </li>
</ul>
</li>
</ul>
The same nesting with bullets. Notice the sub-list sits inside the li, before its closing tag — that is the correct place for it, and it is what makes a hover on the parent reach the child in the next steps.
<style type="text/css">
/* 6) малюнки замість маркерів */
ul.pics {list-style-image:url("images/1.gif");margin-left:60px}
ul.pics ul {list-style-image:url("images/2.gif")}
<!-- 6) малюнки замість маркерів -->
<h2> Турніри </h2>
<ul class="pics">
<li> Major
<ul>
<li> раз на рік </li>
<li> найбільший призовий фонд </li>
</ul>
</li>
<li> ESL Pro League
<ul>
<li> довгий сезон </li>
<li> багато матчів онлайн </li>
</ul>
</li>
</ul>
list-style-image replaces the dot with a picture. The second rule — ul.pics ul — only matches a list inside a list, so the second level gets the other marker.
Marker images are hard to position: they sit on the text baseline and cannot be nudged. The usual way now is list-style:none plus li::before with the picture as a background, where every offset is yours to set.
/* 7) автоматична нумерація рівнів */
ol.auto {list-style-type:none;counter-reset:item}
ol.auto li:before {content:"Розділ " counters(item,".") ". ";counter-increment:item}
<!-- 7) автоматична нумерація -->
<h2> Тактика </h2>
<ol class="auto">
<li> Контроль міду
<ol>
<li> димова в CT-спавн </li>
<li> вихід п'ятьма </li>
</ol>
</li>
<li> Спліт на A </li>
<li> Швидкий вихід на B </li>
</ol>
Here the numbering is not the list's own: counter-reset starts a counter, counter-increment advances it on every item, and counters(item,".") prints the whole chain — 1, then 1.1, 1.2.
li:before means «put this in front of the item's content». The word «Розділ» and the numbers exist only in CSS: there is nothing to select or copy in the HTML.
Which is also the catch. Text generated by CSS is invisible to search and cannot be copied by the reader, so it is for decoration — never for anything the page actually needs to say.
/* 8) список, що розкривається при наведенні */
#mylist ul li ul {display:none}
#mylist ul li:hover ul {display:block}
#mylist ul li:hover {list-style-image:none;font-weight:normal}
#mylist .opening {list-style-image:url("images/1.gif");font-weight:bold;cursor:default}
<!-- 8) список, що розкривається при наведенні -->
<h2> Наведіть курсор на пункт </h2>
<div id="mylist">
<ul>
<li class="opening"> Terrorists
<ul>
<li> закласти бомбу </li>
<li> вистояти до вибуху </li>
</ul>
</li>
<li> Counter-Terrorists </li>
<li class="opening"> Економіка
<ul>
<li> еко-раунд </li>
<li> форс-бай </li>
<li> повна закупівля </li>
</ul>
</li>
</ul>
</div>
Two rules and no script at all: the nested list is display:none until the mouse is on its parent, and then it is display:block. Try it in the preview.
No script means no keyboard either: :hover never fires for someone tabbing through the page, and a touchscreen has no hover at all. A real menu uses a button and aria-expanded so both work.
/* 9) трирівневий список, що розкривається */
#deep ul li ul {display:none}
#deep ul li:hover ul {display:block}
#deep ul li ul li ul {display:none}
#deep ul li ul li:hover ul {display:block}
#deep .opening1 {list-style-image:url("images/2.gif");font-weight:bold;cursor:default}
<!-- 9) трирівневий список, що розкривається -->
<h2> Три рівні </h2>
<div id="deep">
<ul>
<li class="opening1"> Команда
<ul>
<li class="opening1"> Склад
<ul>
<li> п'ять гравців </li>
<li> тренер </li>
</ul>
</li>
<li> Менеджмент </li>
</ul>
</li>
<li> Організація </li>
</ul>
</div>
The same pair of rules written twice, one level deeper. The selector #deep ul li ul li:hover ul reads backwards: a list, inside a hovered item, inside a list, inside an item, inside the block called deep.
/* 10) дворівневе меню, яке розкривається */
#menu ul {list-style-type:none;cursor:default;padding:0}
#menu ul li.opening {float:left;width:120px;height:30px;border-left:solid 1px #f0a500;border-right:solid 1px #f0a500}
#menu ul li ul {display:none;border:solid 1px #f0a500;width:140px;background:#2b2b2b;font-weight:normal;margin-top:10pt;padding:4px}
#menu ul li:hover ul {display:block}
#menu .opening {background:#3a2a1a;text-align:center;font-weight:bold}
#menu a {color:#f0a500}
<!-- 10) дворівневе меню, яке розкривається -->
<h2> Меню карт </h2>
<div id="menu">
<ul>
<li class="opening"> Класика
<ul>
<li><a href="images/1.html"> Dust II </a></li>
<li><a href="images/2.html"> Mirage </a></li>
</ul>
</li>
<li class="opening"> Решта пулу
<ul>
<li><a href="images/3.html"> Inferno </a></li>
<li><a href="images/4.html"> Nuke </a></li>
<li><a href="images/5.html"> Ancient </a></li>
</ul>
</li>
</ul>
</div>
<br clear="all">
A menu is a list with the bullets removed and the top level turned sideways by float:left. The sub-lists stay hidden until hover, exactly as before.
float takes the items out of the normal flow, so <br clear="all"> is needed afterwards to push the rest of the page below them.
float was invented for wrapping text around a picture; using it for layout was a workaround that lasted fifteen years. A menu today is display:flex, and nothing has to be cleared afterwards.
<html><head><meta charset="utf-8"><title> Dust II </title></head> <body> <p> Dust II — найстаріша карта пулу. Усе вирішують довга, катакомби і мід. </p> </body></html>
Five small pages, one per map. The menu items from step 10 link to them, which makes this the first page of the site that actually behaves like a site: a menu that leads somewhere.
<!-- 18) список визначень --> <h2> Словник </h2> <dl> <dt> Еко-раунд </dt> <dd> раунд, у якому команда свідомо не купує зброю, щоб назбирати грошей на наступний. </dd> <dt> Клатч </dt> <dd> ситуація, коли один гравець лишається проти кількох суперників і виграє раунд. </dd> <dt> Спліт </dt> <dd> захід на точку одночасно з двох боків. </dd> </dl>
A third kind of list: dl holds pairs, dt is the term and dd its description. It is meant for glossaries — exactly what this one is.