And voila: A sticky header of arbitrary size above a hero that grows to fill the remaining visible space!<\/p>\n
<\/div>\n
Caveats and Final Thoughts<\/h2>\n
It\u2019s worth noting that the HTML order of the elements matters here<\/strong>. If we define .above-the-fold-spacer<\/code> after our .hero<\/code> section, it will overlay and block access to the elements underneath. We can work around this by declaring either order: -1<\/code>, z-index: -1<\/code>, or visibility: hidden<\/code>.<\/p>\nKeep in mind that this is a simple example. If you were to add a sidebar to the left of your page, for example, you\u2019d need to adjust at which column the elements start. Still, in the majority of cases, using a CSS Grid approach is likely to be less troublesome than the Sisyphean task of manually managing and coordinating the height values of multiple elements.<\/p>\n
Another upside of this approach is that it\u2019s adaptable<\/strong>. If you decide you want a group of three elements to take up the screen\u2019s height rather than two, then you\u2019d make the invisible spacer span three rows and assign the visible elements to the appropriate one. Even if the hero element\u2019s content causes its height to exceed 100vh<\/code>, the grid adapts without breaking anything. It\u2019s even well-supported in all modern browsers.<\/p>\nThe more I think about this technique, the more I\u2019m persuaded that it\u2019s actually quite clean. Then again, you know how lawyers can talk themselves into their own arguments? If you can think of an even simpler solution I\u2019ve overlooked, feel free to reach out and let me know!<\/p>\n
\n

\n
(gg, yk)<\/span>\n<\/div>\n<\/article>\n","protected":false},"excerpt":{"rendered":"Sticky Headers And Full-Height Elements: A Tricky Combination Sticky Headers […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-301","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/posts\/301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":1,"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"predecessor-version":[{"id":302,"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/posts\/301\/revisions\/302"}],"wp:attachment":[{"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blissfuldebt.com\/index.php\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}