Lesson 06 · 7 steps
div.html lays a page out by hand: boxes shifted from where they would naturally fall, boxes that overlap, and boxes pinned to a coordinate. It is also the lesson that shows why nobody builds layouts this way any more.
<!-- 2) відносне позиціонування: три блоки в ряд -->
<style type="text/css">
.blok1 {position:relative;left:0px;margin:0;padding:10px;width:230px;height:120px;background:#2b2b2b;border:outset #f0a500 7px;color:#f0a500}
.blok2 {position:relative;left:260px;top:-140px;margin:0;padding:10px;width:230px;height:120px;background:#2b2b2b;border:inset #8bd450 7px;color:#8bd450}
#blok3 {position:relative;left:520px;top:-280px;margin:0;padding:10px;width:230px;height:120px;background:#2b2b2b;border:ridge #5bb4ff 7px;color:#5bb4ff}
<div class="blok1"> Точка A. Сюди заходять через довгу або через пальму. </div> <div class="blok2"> Мід. Хто тримає мід, той обирає, куди піде раунд. </div> <div id="blok3"> Точка B. Вузький захід, тому все вирішують гранати. </div>
div is a box with no meaning of its own — it exists to be given a size, a colour and a place. position:relative then shifts it from where it would normally sit, by left and top.
That «would normally sit» is the catch: each block still reserves its original space, so moving the second one up by 140px needs a negative top, and the third needs 280px — twice as much. Three boxes in a row cost a line of arithmetic each.
Rows of boxes are not built this way any more. display:flex on the parent puts children in a row by itself, in any order and any width, with no negative numbers involved and nothing to recalculate when the text changes.
/* 3) відносне позиціонування з перекриванням */
#blok4 {position:relative;left:40px;top:-250px;margin:0;padding:10px;width:420px;height:90px;background:#3a2a1a;border:groove #f0a500 7px;color:#ffd9a0}
#blok5 {position:relative;left:300px;top:-290px;margin:0;padding:10px;width:420px;height:90px;background:#1a2a3a;border:groove #5bb4ff 7px;color:#bfe3ff}
<!-- 3) два блоки, які перекривають один одного --> <div id="blok4"> Димова граната закриває огляд на 18 секунд. </div> <div id="blok5"> Світлошумова засліплює на 2–4 секунди, якщо дивитися прямо на неї. </div>
Nothing stops a shifted block from landing on top of its neighbour. Which one is on top depends on the order in the code — later means higher — unless z-index says otherwise.
<!-- 4) абсолютне позиціонування: п'ять блоків --> <div style="position:absolute;left:10px;top:620px;width:500px;height:70px;border-top:solid #f0a500 6px;border-left:solid #f0a500 6px;border-right:solid #f0a500 6px;padding:5px;background:#2b2b2b;color:#f0a500;font-size:13pt"> Рахунок матчу </div> <div style="position:absolute;left:10px;top:706px;width:60px;height:150px;border-left:solid #f0a500 6px;background:#3a2a1a"></div> <div style="position:absolute;left:75px;top:706px;width:391px;height:140px;padding:5px;background:#2b2b2b;color:#e6e6e6;font-size:14pt"> Natus Vincere 13 : 11 Team Spirit. Карта Mirage, перемога в овертаймі. </div> <div style="position:absolute;left:466px;top:706px;width:60px;height:150px;border-right:solid #f0a500 6px;background:#3a2a1a"></div> <div style="position:absolute;left:10px;top:860px;width:500px;height:50px;border-left:solid #f0a500 6px;border-bottom:solid #f0a500 6px;border-right:solid #f0a500 6px;padding:5px;background:#2b2b2b;color:#8bd450;font-size:13pt"> Найкращий гравець матчу: s1mple </div>
position:absolute takes a block out of the flow completely: left and top are now measured from the corner of the page, and the rest of the text behaves as if the block were not there at all.
Which is why this file has an empty #spacer block: the page does not reserve any height for absolutely positioned boxes, so without it the next section would be drawn straight through them.
Measuring from the corner of the page means the layout is nailed to one window size. A page built like this cannot reflow on a phone — which is the reason the whole technique was replaced by grid and flex for layout, and absolute kept for small things: a badge on a card, a tooltip, a close button.
<!-- 5) абсолютне позиціонування: блоки один над другим --> <div align="center" style="position:absolute;left:560px;top:620px;width:420px;height:290px;border:groove #8bd450 10px;padding:10px;background:#1b1b1b;color:#8bd450;font-size:20pt"> Ролі в команді </div> <div align="justify" style="position:absolute;left:580px;top:680px;width:120px;height:200px;padding:5px;background:#2b2b2b;color:#e6e6e6;font-size:13pt"> entry fragger заходить першим і відкриває простір. </div> <div align="justify" style="position:absolute;left:720px;top:680px;width:120px;height:200px;padding:5px;background:#333;color:#e6e6e6;font-size:13pt"> AWPer тримає довгу лінію й ламає захід суперника. </div> <div align="justify" style="position:absolute;left:860px;top:680px;width:120px;height:200px;padding:5px;background:#2b2b2b;color:#e6e6e6;font-size:13pt"> IGL придумує тактику й вирішує за всіх п'ятьох. </div>
One big box and three smaller ones sitting on it. The parent is drawn first, so the children land on top; each child has its own coordinates, which is exactly why they can sit inside the parent without being inside it in the code.
<!-- 7) повернення на головну сторінку --> <a href="main.html"> головна сторінка </a>
The same pair of links as in lesson 5. By now the site is six pages that all know the way back.