Lytbox Academy Logo
Lytbox Academy Logo

How To Create A Shrinking Sticky Header On Scroll With Elementor

Article Outline

In this tutorial you will learn how to create a shrinking header, shrinking logo, shrinking menu & shrinking button on scroll with Elementor sticky headers.

Last edited 29/08/2023: For elementor containers, we need to add a specific height before and after shrinking.

Check out the live example 👉 https://tuts.lytboxacademy.com/shrinking-header/

What is a Shrinking Sticky Header with Elementor

A shrinking sticky header using Elementor is a cool effect on a menu. Well, actually, it’s a combination of two effects. So let’s break them down to make them easier to understand.

A sticky header is an effect when you scroll a website, the menu and header stick to the top of the page. This makes it much easier for the website’s viewer to navigate around a website. And using Elementor to make a sticky header can be simple even for a newbie.

A Shrinking header is an effect when the user scrolls down the web page, and the menu items shrink, making the header smaller and taking up less space. This effect is also ideal for a better user experience as it reduces the size of a header allowing more of the webpage to show.

In this tutorial, we will make it easy and show you how to do this on your website using only Elementor and Elementor Pro to create a shrinking sticky header on scroll effect. Of course, there’s a little bit of CSS to copy and paste, but not to worry, even a beginner can follow along and build this.

Why Use a Shrinking Sticky Header on Scroll with Elementor

There’s a simple answer to this. A sticky header combined with a shrinking effect improves the usability of a website. Making a site easier to navigate which leads to a better user experience.

What You’ll Need For This Tutorial

You’ll need Elementor and Elementor Pro. Yeah, you’ll need the pro version, and I know it costs a bit, but to really use and unlock the power and potential of Elementor, the pro version is needed.

You’ll also need to understand how to build a header with Elementor. If you’d like to learn more about building a header With Elementor, I have quite a few video tutorials here.

Where To Add CSS For This Tutorial

For this tutorial, we will need to add some CSS. However, it’s simple, and you don’t even need CSS knowledge. Just copy and paste, and I will show you where to edit to adjust your effects.

Add your CSS to the Customizer or in Elementor’s CSS located in Elementor Settings. See the images below.

For more information about adding CSS, you can check this out here.

How To Create a Sticky Header On Elementor

First, make sure to have your header built. Then, after your header is completed, select to edit your Section (or outer Container if you are using containers).

Next, navigate to the Advanced tab and select Motion Effects. Then, in the Sticky option, select Top.

Next, choose if you will have your header sticky on Desktop, Tablet, and Mobile. In the video tutorial, I show how to make your header sticky and shrink for mobile, so make sure to check it out!

And next, this part is super important, add a number value to the Effects Offset. The Effects Offset determines how far the web page needs to be scrolled for the sticky effects to kick in. What number you put here is the number of pixels the page needs to scroll. A good number is between 60-120.

How To Make Your Sticky Header Shrink On Scroll

In this next part, we’ll start to add effects to our sticky header with Elementor. We will make our logos, menus, call to action button, and overall header section shrink. Then, I’ll break down each section so you can apply only what you need.

Make the Header Section Shrink On Scroll With Elementor

To start, we need to give a class to the section (or container) that is wrapping our header. This is a must to make sure the CSS works. Only the elements, logo, menu, and button will shrink in a single section (or container), wrapping everything.

Select to edit your Section (or Container) and navigate to the Advanced tab. Then go down to your CSS Classes and add in “shrinker”. See the image below.

Copy and paste the CSS below. Now, there’s a little bonus in this CSS. I added an option to change the color of your menu on scroll as well!

/* shrinking header section */

.shrinker {
	background: transparent;
        height: (set your header height in pixels);
	transition: all .2s linear!important;
	-webkit-transition: all .2s linear!important;
	-moz-transition: all .2s linear!important;
}

.shrinker.elementor-sticky--effects {
	background: #fff;
        height: (set your header height after shrinking in pixels)!important;
	padding-top: 2px!important;
	padding-bottom: 2px!important;
	box-shadow: 0px 6px 30px -4px rgba(0,0,0,.05);
	transition: all .2s linear!important;
	-webkit-transition: all .2s linear!important;
	-moz-transition: all .2s linear!important;
}

How to Change Your Header Background Color On Scroll with Elementor

I’ve added a bonus effect to this tutorial. We can use the CSS snippet below to change the header’s background color on scroll with Elementor. You can start with a transparent background on your header and give it a solid color on scroll. Or you can simply change the colors. I have also added an additional option for mobile so we can add an extra color for mobile header background colors.

In this first snippet where you see “background: transparent;”, this will be the initial header background. If you are not using a transparent header and have a colored background, you will need to change “transparent” to the color of your background.

In the next section where you see “background: # fff;”, you will need to change this to the color of the background you’d like to have when it scrolls down.

And if you don’t want to change the colors of your header background, you can simply delete both lines of CSS.

Also, the box shadow is optional. I think it looks cool and gives a bit of depth to a sticky menu. But it’s completely optional. You can remove it if you don’t want to use it. No hard feelings.

To make the sticky header shrink with Elementor:

To make the header section shrink, we will target the top and bottom padding. In my header, I use padding to create space. So make sure to use padding, not margins.

My padding is set to 12px top and bottom. To make the header shrink, we will reduce the padding to 2px. This will create a big shrink.

To adjust the shrink, edit “padding-top: 2px!important; and. padding-bottom: 2px!important;”. Only change the 2px to what looks right for your header.

And you may be wondering why so many “transition: all .2s linear!important;”. This is the code used to make the shrinking have a smooth animation. If you weren’t to change the speed of the animation, you could edit the “.2s” which stands for .2 seconds. You can make it animate faster by changing it to .1s or go slower by changing it to .5s. Or you can just let it be and trust my judgment of this being a sweet spot for animations.

How to Make a Logo Image Shrink On Scroll With Elementor

Shrinking the logo or any image on scroll with Elementor will have the biggest effect on the overall header shrinking since it’s usually the largest element in your header.

To start, let’s give a class called “shrinking-logo” to our logo. And just a heads up, I always use an image widget for my logos, not the logo widget. It’s more flexible.

Navigate to the advance tab and add “shrinking-logo” to the CSS Classes (without the “”).

Now copy and paste in this CSS Snippet.

/* shrinking logo image */

.shrinking-logo img {
	width: 150px!important;
	transition: all .2s linear!important;
	-webkit-transition: all .2s linear!important;
	-moz-transition: all .2s linear!important;
}

.shrinker.elementor-sticky--effects img {
	width: 120px!important;
	transition: all .2s linear!important;
	-webkit-transition: all .2s linear!important;
	-moz-transition: all .2s linear!important;
}

All that needs to be edited in the code is the “width: 150px!important;”.

The first “width: 150px!important;” is your original size. This will overwrite what size you set your logo in Elementor, but it is the only way to make the animation smooth. Just change the “150px” to the size you want your logo.

The second “width: 120px!important;” is the size it will shrink to. Again, feel free to adjust the ”120px” to the size you want your logo to shrink to.

And the same goes for the mobile size “width: 100px!important;”. Change this for your phone-sized logo but just a tip, look at how it’s coming out on your phone and adjust from what you see there.

How to Make a Menu Shrink On Scroll With Elementor

This method works for both the Menu Widget and Icon List Widget in Elementor.

This is a lot easier than the image because no class needs to be given. We already have the class in the section to target our menu and buttons.

Simply add the CSS below. And what you would edit to make the menu shrink is the font size.

/* shrinking menu */

.shrinker.elementor-sticky--effects ul li a {
	font-size: .9rem!important;
	transition: all .2s linear!important;
	-webkit-transition: all .2s linear!important;
	-moz-transition: all .2s linear!important;
}

In the part “font-size: .9rem!important;” all you need to edit is the .9rem. My original menu has a font size of 1rem. All we want to do here is make it shrink ever so slightly. For example, if your menu is 18px, shrink it down to 16px, and it will have a cool effect but still stay usable.

How to Make a Button Shrink On Scroll With Elementor

After shrinking the logo and menu, this should start to get easier. Just copy and paste the CSS below. What we are looking to edit is the button’s padding – “padding: 10px 32px!important;”.

/* shrinking button */

.shrinker.elementor-sticky--effects .elementor-button {
	padding: 10px 32px!important;
	transition: all .2s linear!important;
	-webkit-transition: all .2s linear!important;
	-moz-transition: all .2s linear!important;
}

On my site, the original padding was 16px 48px. We need to reduce the padding’s px, and we have a shrinking button!

Adding Mobile & Tablet CSS

For this next part, it may be helpful to watch the walkthrough video below to help walkthrough and explain editing the responsive CSS.

/* Tablet and Mobile Menu Shrinking */

@media screen and (max-width: 1024px) {
	/* shrinking background */
	
.shrinker.elementor-sticky--effects {
	background: #fff;
	padding-top: 2px!important;
	padding-bottom: 2px!important;
	box-shadow: 0px 6px 30px -4px rgba(0,0,0,.05);
}
	
	/* shrinking image */

.shrinker.elementor-sticky--effects img {
	width: 100px!important;
}
	
	/* shrinking menu */

.shrinker.elementor-sticky--effects ul li a {
	font-size: 1.2rem!important;
}

/* shrinking button */

.shrinker.elementor-sticky--effects .elementor-button {
	padding: 10px 32px!important;
}
}

/* End Of Shrinking Sticky Menu */

Shrinking Sticky Header With Elementor Video Tutorial

To make this all easier and faster, I made a video tutorial. The video shows how I built my menu and set up a sticky shrinking menu for mobile. I hope this helps, and if it does, you can return the love with a subscription. Cheers!

YouTube video

Join the Lytbox Newsletter

Blog Page Sign Up

17 comments

  • Hi – I was getting a bug using the code for the shrinking header, caused by the transition property. Using `transition: all` was preventing the nav from resizing the width properly. If I make my browser window smaller and then make it full size again, the nav would remain at the smaller width, leaving a gap on the sides. I changed all the transition properties to `transition: height` to fix this. Just noting this in case anyone else experiences a similar bug.

    1
    • Diego Guillen

      Can you share the code?

      0
      • M. Jordan

        Simply replace ALL ‘transition: all’ with ‘transition: height’

        Before:
        transition: all .2s linear!important;
        -webkit-transition: all .2s linear!important;
        -moz-transition: all .2s linear!important;

        after:

        transition: height .2s linear!important;
        -webkit-transition: height .2s linear!important;
        -moz-transition: height .2s linear!important;

        Important: Don’t forget the webkit- and the moz-transition !

        1
  • Hey, any idea why my header is growing instead of shrinking? I have 20px padding top and bottom set on the container and put 6px each in the css for shrinking. But its growing on scroll now.

    0
    • Hey Caro, could you please share the link to your site and your CSS too?

      0
      • Hey, thanks for the quick reply. The page is under construction mode. I could give you credentials to have a look, but i would need an email address. Its built with wordpress and elementor. The CSS was only and just what you have here. I copy and pasted it and changed the 2px to 6px, thats all. Shrinking the logo worked btw. Only the header itself is growing.

        0
        • Hey Caro,

          I have new findings. If you are using containers for your header, then you have to set a height in the “.shrinker” class. Then add the height you want your header to be after shrinking inside the “.shrinker.elementor-sticky–effects” class. Make sure to add it before the transition properties.

          Let me know if this solves your problem 🙂

          1
        • Hi Caro,

          Apologies, but we don’t access other websites unless they are clients.

          What I would suggest is to take a good look at the states of the header, before scrolling and while scrolling. Which values are changing and changing to what? Make sure you use the same units (%, px, etc.) for both states. Check all the elements inside the header to see if any element is increasing in size, which might cause the header to become bigger too.

          Happy Debugging 🙂

          0
          • Hey Partho, thanks a ton! I havent tried yet, but i definitely will and let you know about the results.

            0
  • Great Tutorial! The first one that made sense … and I have seen many of those shrinking header ones. However, there is one thing. If I modify the css growing the header works but shirking the header does not. I have followed everything you’ve said … but obviously I am missing something. I am using Flexbox Containers and all the right settings. Any ideas?

    Thank you so much!

    0
    • Hey Vasken, could you please explain what you are trying to achieve in detail and also share your CSS?

      0
  • First of all, you are definitely the best Elementor Youtube channel for me! Your tutorials are extremely helpful and easy to understand, I look forward to every new video from you! Regarding your instructions with the sticky header, is it also possible to change the image of the logo via CSS while scrolling? I am using a white logo on a transparent background and when scrolling the background of the header turns white and I would like to include the black logo instead of the white one. Is something like this possible?

    0
  • Ari Miller

    GREAT tutorial! A real life saver for me!

    One question…
    I’m trying to apply the same concept to a tagline. I added a Header widget to my shrinking header. I added a CSS class of shrinker-tagline and the following to my customer CSS –

    .shrinker.elementor-sticky–effects .shrinker-tagline {
    font-size: 20px!important;
    padding: 10px!important;
    transition: all 1s linear!important;
    -webkit-transition: all 1s linear!important;
    -moz-transition: all 1s linear!important;
    }

    No bueno 🙁
    Any suggestions?

    0
    • A
      TheJediNinja

      Hey Ari, can you send a link to your website? I’d like to see this in the dev tools

      0
      • Thank you so much for your quick response and offer to take a look. What a boost in my general hope for humanity! Great meeting good people.

        I actually got the header to work! A bit more CSS fooling around and boom!!

        I would still love you to take a look at what I’m working on. I will add you as an editor to the site. It’s in development at the moment so don’t mind the mess. Can I get an email address to add you and share credentials? I have a construction page on the public side.

        You’ll see what I’m trying to do – my header contains an background image. I use padding to control the size of the header. I have the shrinking operation close to what I want, but when it shrinks, it leaves an empty space where the height used to be until the scroll fills the gap. Easy to understand when you see it.

        Thanks again and I’ll look to hear from you!

        0
  • Great Tutorial, Thanks a lot!

    1

Leave your comment


Join the Lytbox Newsletter
Blog Page Sign Up
Lytbox Academy Logo

Reset your passord

Want to login? Click here.
Lytbox Academy Logo

Log in to your account

Forgot your password? Reset here.