{"id":370,"date":"2024-09-05T09:00:00","date_gmt":"2024-09-05T09:00:00","guid":{"rendered":"https:\/\/kerrprogroup.com\/?p=370"},"modified":"2025-03-19T12:20:49","modified_gmt":"2025-03-19T12:20:49","slug":"sticky-headers-and-full-height-elements-a-tricky-combination","status":"publish","type":"post","link":"https:\/\/kerrprogroup.com\/index.php\/2024\/09\/05\/sticky-headers-and-full-height-elements-a-tricky-combination\/","title":{"rendered":"Sticky Headers And Full-Height Elements: A Tricky Combination"},"content":{"rendered":"
Sticky Headers And Full-Height Elements: A Tricky Combination<\/title><\/p>\n\n\n
Sticky Headers And Full-Height Elements: A Tricky Combination<\/h1>\nPhilip Braunen<\/address>\n
I was recently asked by a student to help with a seemingly<\/em> simple problem. She\u2019d been working on a website for a coffee shop that sports a sticky header, and she wanted the hero section right underneath that header to span the rest of the available vertical space in the viewport.<\/p>\n
Here\u2019s a visual demo of the desired effect for clarity.<\/p>\n\n
<\/div>\n<\/figure>\n
Looks like it should be easy enough, right? I was sure (read: overconfident) that the problem would only take a couple of minutes to solve, only to find it was a much deeper well than I\u2019d assumed.<\/p>\n
Before we dive in, let\u2019s take a quick look at the initial markup and CSS to see what we\u2019re working with:<\/p>\n
\n Header Content<\/header>\n Hero Content<\/section>\n Main Content<\/main>\n\n<\/code><\/pre>\n
.header {\n position: sticky;\n top: 0; \/* Offset, otherwise it won't stick! *\/\n}\n\n\/* etc. *\/\n<\/code><\/pre>\n
With those declarations, the .header<\/code> will stick to the top of the page. And yet the .hero<\/code> element below it remains intrinsically sized. This is what we want to change.<\/p>\n