tailwind1-4 Exercise 2: A Sticky Footer, with Centred Content
==============================================================
Part 1: the sticky footer.
Welcome
Centred in the space between header and footer.
Measure the middle of the block against the middle of main:
const m = R('main'), b = R('blk');
console.log({ blockCentreY: b.top + b.height / 2, mainCentreY: m.top + m.height / 2, blockCentreX: b.left + b.width / 2 });
Output:
footerBottom 405, main from 64 to 357, blockCentreY 210.5, mainCentreY 210.5, blockCentreX 450 (the page is 900px wide)
WHY THIS WORKS AS AN ANSWER
---------------------------
min-h-dvh makes the body at least as tall as the visible screen, and flex-col stacks header, main and footer. flex-1 is flex: 1, so main takes all the free height:
405 - 64 (header) - 48 (footer) = 293. The footer is then pushed to the very bottom, 405. Without flex-1, main is only as tall as its content (56px), the footer
follows it, and the free space is left below the footer.
For the centred block, main has already been stretched by flex-1 to 293px, so making main itself a grid with place-items-center centres the block in that box:
the block's centre (210.5) equals main's centre (64 + 293/2 = 210.5), and horizontally it is at 450, the middle of the 900px page. flex-1 plus grid on the same
element is fine: flex-1 is about how main behaves as a child of the body (a flex item), while grid place-items-center is about how main arranges its own children.