Sticky Headers And Full-Height Elements: A Tricky Combination

Category Image 080

I was recently asked by a student to help with a seemingly simple problem. She’d 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.

Here’s a visual demo of the desired effect for clarity.

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’d assumed.

Before we dive in, let’s take a quick look at the initial markup and CSS to see what we’re working with:

<body>
<header class=”header”>Header Content</header>
<section class=”hero”>Hero Content</section>
<main class=”main”>Main Content</main>
</body>

.header {
position: sticky;
top: 0; /* Offset, otherwise it won’t stick! */
}

/* etc. */

With those declarations, the .header will stick to the top of the page. And yet the .hero element below it remains intrinsically sized. This is what we want to change.

The Low-Hanging Fruit

The first impulse you might have, as I did, is to enclose the header and hero in some sort of parent container and give that container 100vh to make it span the viewport. After that, we could use Flexbox to distribute the children and make the hero grow to fill the remaining space.

<body>
<div class=”container”>
<header class=”header”>Header Content</header>
<section class=”hero”>Hero Content</section>
</div>
<main class=”main”>Main Content</main>
</body>

.container {
height: 100vh;
display: flex;
flex-direction: column;
}

.hero {
flex-grow: 1;
}

/* etc. */

This looks correct at first glance, but watch what happens when scrolling past the hero.

See the Pen Attempt #1: Container + Flexbox [forked] by Philip.

The sticky header gets trapped in its parent container! But.. why?

If you’re anything like me, this behavior is unintuitive, at least initially. You may have heard that sticky is a combination of relative and fixed positioning, meaning it participates in the normal flow of the document but only until it hits the edges of its scrolling container, at which point it becomes fixed. While viewing sticky as a combination of other values can be a useful mnemonic, it fails to capture one important difference between sticky and fixed elements:

A position: fixed element doesn’t care about the parent it’s nested in or any of its ancestors. It will break out of the normal flow of the document and place itself directly offset from the viewport, as though glued in place a certain distance from the edge of the screen.

Conversely, a position: sticky element will be pushed along with the edges of the viewport (or next closest scrolling container), but it will never escape the boundaries of its direct parent. Well, at least if you don’t count visually transform-ing it. So a better way to think about it might be, to steal from Chris Coyier, that “position: sticky is, in a sense, a locally scoped position: fixed.” This is an intentional design decision, one that allows for section-specific sticky headers like the ones made famous by alphabetical lists in mobile interfaces.

See the Pen Sticky Section Headers [forked] by Philip.

Okay, so this approach is a no-go for our predicament. We need to find a solution that doesn’t involve a container around the header.

Fixed, But Not Solved

Maybe we can make our lives a bit simpler. Instead of a container, what if we gave the .header element a fixed height of, say, 150px? Then, all we have to do is define the .hero element’s height as height: calc(100vh – 150px).

See the Pen Attempt #2: Fixed Height + Calc() [forked] by Philip.

This approach kinda works, but the downsides are more insidious than our last attempt because they may not be immediately apparent. You probably noticed that the header is too tall, and we’d wanna do some math to decide on a better height.

Thinking ahead a bit,

What if the .header’s children need to wrap or rearrange themselves at different screen sizes or grow to maintain legibility on mobile?
What if JavaScript is manipulating the contents?

All of these things could subtly change the .header’s ideal size, and chasing the right height values for each scenario has the potential to spiral into a maintenance nightmare of unmanageable breakpoints and magic numbers — especially if we consider this needs to be done not only for the .header but also the .hero element that depends on it.

I would argue that this workaround also just feels wrong. Fixed heights break one of the main affordances of CSS layout — the way elements automatically grow and shrink to adapt to their contents — and not relying on this usually makes our lives harder, not simpler.

So, we’re left with…

A Novel Approach

Now that we’ve figured out the constraints we’re working with, another way to phrase the problem is that we want the .header and .hero to collectively span 100vh without sizing the elements explicitly or wrapping them in a container. Ideally, we’d find something that already is 100vh and align them to that. This is where it dawned on me that display: grid may provide just what we need!

Let’s try this: We declare display: grid on the body element and add another element before the .header that we’ll call .above-the-fold-spacer. This new element gets a height of 100vh and spans the grid’s entire width. Next, we’ll tell our spacer that it should take up two grid rows and we’ll anchor it to the top of the page.

This element must be entirely empty because we don’t ever want it to be visible or to register to screen readers. We’re merely using it as a crutch to tell the grid how to behave.

<body>
<!– This spacer provides the height we want –>
<div class=”above-the-fold-spacer”></div>

<!– These two elements will place themselves on top of the spacer –>
<header class=”header”>Header Content</header>
<section class=”hero”>Hero Content</section>

<!– The rest of the page stays unaffected –>
<main class=”main”>Main Content</main>
</body>

body {
display: grid;
}

.above-the-fold-spacer {
height: 100vh;
/* Span from the first to the last grid column line */
/* (Negative numbers count from the end of the grid) */
grid-column: 1 / -1;
/* Start at the first grid row line, and take up 2 rows */
grid-row: 1 / span 2;
}

/* etc. */

This is the magic ingredient.

By adding the spacer, we’ve created two grid rows that together take up exactly 100vh. Now, all that’s left to do, in essence, is to tell the .header and .hero elements to align themselves to those existing rows. We do have to tell them to start at the same grid column line as the .above-the-fold-spacer element so that they won’t try to sit next to it. But with that done… ta-da!

See the Pen The Solution: Grid Alignment [forked] by Philip.

The reason this works is that a grid container can have multiple children occupying the same cell overlaid on top of each other. In a situation like that, the tallest child element defines the grid row’s overall height — or, in this case, the combined height of the two rows (100vh).

To control how exactly the two visible elements divvy up the available space between themselves, we can use the grid-template-rows property. I made it so that the first row uses min-content rather than 1fr. This is necessary so that the .header doesn’t take up the same amount of space as the .hero but instead only takes what it needs and lets the hero have the rest.

Here’s our full solution:

body {
display: grid;
grid-template-rows: min-content 1fr;
}

.above-the-fold-spacer {
height: 100vh;
grid-column: 1 / -1;
grid-row: 1 / span 2;
}

.header {
position: sticky;
top: 0;
grid-column-start: 1;
grid-row-start: 1;
}

.hero {
grid-column-start: 1;
grid-row-start: 2;
}

And voila: A sticky header of arbitrary size above a hero that grows to fill the remaining visible space!

Caveats and Final Thoughts

It’s worth noting that the HTML order of the elements matters here. If we define .above-the-fold-spacer after our .hero section, it will overlay and block access to the elements underneath. We can work around this by declaring either order: -1, z-index: -1, or visibility: hidden.

Keep in mind that this is a simple example. If you were to add a sidebar to the left of your page, for example, you’d 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.

Another upside of this approach is that it’s adaptable. If you decide you want a group of three elements to take up the screen’s height rather than two, then you’d make the invisible spacer span three rows and assign the visible elements to the appropriate one. Even if the hero element’s content causes its height to exceed 100vh, the grid adapts without breaking anything. It’s even well-supported in all modern browsers.

The more I think about this technique, the more I’m persuaded that it’s 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’ve overlooked, feel free to reach out and let me know!

WordPress Roundup: August 2024

Featured Imgs 23

Welcome to the WordPress Roundup, your monthly digest of the latest news and updates from the WordPress community. We bring you essential WordPress developments for all experience levels each month, keeping you informed about the latest core updates and upcoming releases. Whether you’re a seasoned developer, a dedicated site owner, or launching your first WordPress

The post WordPress Roundup: August 2024 appeared first on WP Engine.

WP Engine Appoints Samuel Monti as its Chief Financial Officer

Featured Imgs 23

AUSTIN, Texas—SEPT. 5, 2024—WP Engine, a global web enablement company providing premium products and solutions for websites built on WordPress, today announced the hiring of a new Chief Financial Officer, Samuel (“Sam”) Monti. In his new role, Monti is responsible for the leadership and management of all aspects of WP Engine’s financial organization, including corporate

The post WP Engine Appoints Samuel Monti as its Chief Financial Officer appeared first on WP Engine.

20+ Best Cinematic Color Grading Presets (For DaVinci, Premiere + More)

Featured Imgs 23

Cinematic color grading is all about creating mood, atmosphere, and emotion in your visual narratives. It’s what separates ordinary footage from the breathtaking scenes you see in blockbuster films.

However, mastering color grading can be a complex and time-consuming process. That’s why high-quality presets are a game-changer, offering an efficient way to apply sophisticated looks to your videos with just a few clicks.

In this post, we’ve compiled a selection of the best cinematic color grading presets for popular platforms like DaVinci Resolve, Premiere Pro, and more. Each preset is carefully chosen for its ability to deliver stunning, film-like quality across a variety of styles, from dramatic and moody tones to vibrant, colorful palettes.

Check out the collection below and be sure to download the free LUTs as well.

30 CINEMATIC LUTS for Color Grading

This is a must-have collection of cinematic color grading presets offering 30 professional cinematic color looks designed for any Rec709 color space videos. It also includes a LUT converter for Vlog, Dlog, and Slog to Rec709. Utilize them to infuse color grading effects into your clips, enhancing the visual storytelling. A video tutorial accompanies this pack, simplifying the process for beginners.

Movie Tones Cinematic Color LUTs

This is an impressive array of color grading presets designed to add that bold, movie-like look to your footage. These color grading LUTs can transform your video content into a cinematic masterpiece with a simple click. The LUTs offer color tones ideal for enhancing visual storytelling.

Movie LUTs Color Presets

You can use this cinematic color grading preset pack to achieve Hollywood-movie-like color grading for photos and videos. Compatible with popular software like Adobe Premiere Pro, Adobe After Effects, Davinci Resolve, and Final Cut Pro, these presets work perfectly with any FPS and resolution as well as drone cameras.

Bold Cinematic Color Presets

This pack of cinematic color grading presets includes versatile LUTs, ideal for photo and video, including drone footage. They function with any FPS and resolution, require no plugins, and are compatible with many popular software, including Adobe Premiere Pro, After Effects, Davinci Resolve, and Final Cut Pro. Easy to use, they can enhance numerous media projects, from production videos to special events.

Cinematic Wedding Color LUTs

A creative color grading preset pack perfect for enhancing wedding videos. This LUTs pack helps to achieve cinematic color grading quickly, bringing a professional touch to your footage. It’s a practical solution for adding depth and charm to precious memories, making them even more memorable. This tool is simple to use yet impactful, guaranteed to elevate your wedding videos.

Cinematic Movie Color LUTs

A unique creative cinematic color grading preset bundle that adds a colorful cinematic touch to your projects. Offering a collection of different color profiles, it ensures your work stands out with aesthetically appealing and professional-looking visuals. It’s incredibly versatile and user-friendly, making it perfect for film enthusiasts and content creators aiming for a high-quality cinematic look.

Film Color Grading LUTs Pack

This color grading preset pack is ideal for rendering a cinematic touch to your visuals. It offers color look-up tables (LUTs) specially designed for film-like color grading looks. These presets are an investment that simplifies your post-production process, enhancing your visuals with the texture and depth of professional film aesthetics.

Cinematic Film Color Grading Presets

A creative collection of color grading presets that provides cinematic color Look-Up Tables (LUTs). This bundle offers modern cinematic visual styles, enhancing your videos with the rich, dramatic tones often associated with professional cinema projects. It’s a great asset for adding a touch of Hollywood flair to your film and video creations.

Modern Cinematic Film LUTs

A creative resource that offers bold cinematic color grades to your films. It transforms your footage into a visually stunning cinematic experience, capturing the essence of tried-and-true film aesthetics. With this asset, creating a compelling visual narrative becomes seamless and straightforward. It’s an essential tool to elevate your film production.

Classic Film Cinematic Color Grading LUTs

This is a creative color grading preset pack that offers a vintage touch to your visuals. These cinematic color Look-Up Tables (LUTs) allow you to transform the color and tone of your media, mimicking the timeless appearance of classic films. A great tool for enhancing your projects with nostalgia-inducing, cinematic flair.

Cinematic Film LUTs Pack

A creative color grading preset pack designed to enhance your visuals with bright cinematic color grades. The presets are highly recommended for elevating the overall aesthetics of your footage, giving you professional-grade cinematic looks in a user-friendly package. Perfect for filmmakers and content creators seeking to level up their projects.

Aerial Cinematic LUTs for Drone Videos

This LUTs pack is designed to transform drone footage into captivating cinematic stories. This pack, tailored for Final Cut Pro X and Apple Motion, includes 21 expertly created LUTs. Incorporating them into your work is straightforward, thanks to the user-friendly controls of the editing software. They help to enhance storytelling with stunning color grading.

Slog2 Cinematic and Standard Color LUTs

An ideal color grading preset collection for enhancing your wide dynamic range videos. These creative tools allow you to achieve that coveted cinematic look, elevating the visual storytelling of your content. Simple to use yet powerful, they promise to transform your footage, adding depth, mood, and captivating color tones to your creative projects.

Blast Cinematic Movie LUTs

Spruce up your videos with this cinematic movie LUTs pack. This pack features 25 cinematic LUTs and 42 “Log to Rec 709” LUTs perfect for films, social videos, presentations, and more. Adding a tasteful color grading to your work is as easy as drag-and-drop, no matter the resolution. Boasting improved modern and stylish visuals, this pack is a true game-changer.

Cinematic Color Grading LUTs Pack

An exciting collection of color grading presets that transforms your video footage with a film-style look. This pack contains unique cinematic LUTs that give your projects an amazing, visually striking dimension. It’s ideal for filmmakers and videographers seeking to elevate their storytelling abilities through immersive, cinema-quality aesthetics.

Vibrant Cinematic Color LUTs

Give your videos a cinematic edge with this professional LUTs collection. Designed specifically for DaVinci Resolve, this pack of 24 high-quality lookup tables enhances colors, boosts contrast, and lends a professional polish to your film projects. Turn ordinary footage into a visual delight and create cinematic masterpieces effortlessly with these LUTs.

70 Cinematic Color Grading LUTs

This bundle offers an easy way to bring professional, film-like aesthetics to your video content. Compatible with various editing software and cameras, these presets enable an outstanding color grading potential with just a few clicks. Whether it’s footage for YouTube, an independent film, or music videos, these LUTs can utterly transform and enhance your visuals.

1000 Cinematic Color Presets Bundle

This color grading preset pack delivers a variety of LUTs to transform your videos into cinematic works of art. Offering 1000 unique presets spread across categories like cinematic, vintage, and travel, the bundle supports popular video editors, including Premiere Pro and After Effects. Beyond color grading, the bundle provides 15 unique VHS looks, 5 old film looks, and light leaks to add a retro touch to your content.

Free Cinematic Color Grading Presets

70 FREE LUTs for Cinematic Color Grading

This is a collection of 70 color-grading LUTs for videos. It includes a wide variety of color looks, including cinematic looks, to give your video projects a professional look. There are also 17 LUTs for enhancing Log footage.

48 FREE Custom LUTs for Log Footage

A hand-crafted bundle of color-grading LUTs for improving and optimizing log footage. This pack includes 48 different LUTs for making your videos look professional. They feature vintage and cinematic filters as well.

29 Free LUTs for Videos

This video LUTs bundle also comes with a mixed collection of color grading presets for both optimizing and enhancing your videos. It includes 29 different LUTs that feature high-quality color looks and filters.

Free Cinematic LUTs for Photos & Videos

This free LUTs pack is designed to give a cinematic look and feel to your videos and photos. It includes several color-grading LUTs with professional-looking filters that will instantly enhance your videos with a more dramatic look.

Node.js or Laravel in 2024: Decoding the Best Framework for Your Next Project

Featured Imgs 23

In the ever-evolving landscape of web development, choosing the right framework is crucial for the success of your next project. As we dive into 2024, two popular frameworks often come up in discussions: Node.js and Laravel. Both have their unique strengths and are suitable for different types of projects. In this article, we’ll dissect their …

The post Node.js or Laravel in 2024: Decoding the Best Framework for Your Next Project first appeared on Lucid Softech.