Sticky/Fixed Header and Navigation for Debut Theme

SeanP
Shopify Staff
Shopify Staff
2 0 47

Caution

This is an advanced tutorial and is not supported by Shopify. It is specific to an unedited version of the Debut theme, released 7th of March. We cannot guarantee results for themes that have been modified with custom coding and/or apps.

We suggest hiring a Shopify Expert if you are not comfortable proceeding with the following tutorial, or wish to make any variations to this tutorial. We would also advise making a backup of your theme.

Having a sticky header means that the navigation, logo, and icons will follow the user while they scroll down the page. This is really useful if you want to ensure that your customers will have easy access to your navigation at all times! Let’s take a look at how to implement this for the Debut theme.

Note

We recommend having your header set as Logo Alignment: Left. This is the default setting for the Debut Theme but it can be changed. To do this, you would need to open the Theme Editor.
On the left-hand side, click on the Header section and, from here, you will be able to change the alignment.

12-00-q35ps-rsk5r

This is an important step, as the header will be shown on every portion of the page as you scroll. Setting the logo alignment to left will ensure the header takes up less space on the screen. We also can't ensure that the customization will work if this setting is not activated.

If you have an Announcement bar, and would like for it to not move with the rest of the header, please refer to option 2 of this guide.

 

OPTION 1 - STICKY HEADER

This will make the whole header sticky, including the announcement bar.


11-29-y1xka-8hyx2

  1. From your Shopify admin, go to Online Store > Themes.
  2. Locate your Debut theme and then click Actions > Edit code.
  3. In the Assets folder, open your theme.scss.liquid file.

    03-39-badae-sysyp
  4. Go to the very bottom of this file and paste the following code:

    #SearchDrawer {
      z-index:1001;
    }
    
    #shopify-section-header {
      position: fixed;
      z-index:1000;
      left:0;
      right:0;
      -webkit-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      -moz-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      -ms-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      -o-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      background-color: {{ settings.color_body_bg }};
    }
    
    #PageContainer {
      padding-top: 80px;
    }
    
    @media screen and (max-width: 749px) {
    #PageContainer {
      padding-top: 70px;
    }
    }
    
  5. In the same Assets folder, click to open your theme.js file.
  6. Go to the very bottom of this file and paste the following code:

    function headerSize() {
      var $headerHeight = $('div#shopify-section-header').outerHeight();
      $('#PageContainer').css('padding-top', $headerHeight);
    }
    
    $(window).on("load", headerSize);
    $(window).on("resize", $.debounce(500, headerSize));
    
  7. Ensure that the code was copied exactly from this guide and pasted correctly, making sure no characters or symbols are missing.
  8. Save the file by using the button on the top right-hand side.
  9. Refresh your online store page and verify that the sticky header is working correctly!

And that's it! If you would prefer for the announcement bar to not scroll with the user, then you would need to follow the steps below.

 

OPTION 2 - STICKY HEADER WITHOUT THE ANNOUNCEMENT BAR

Note

In this section of the guide, we are assuming that you did not use the code above. If you have used it previously to make the whole header sticky, then you would need to revert your changes to make sure that you are working on an untouched theme.

  1. From your Shopify admin, go to Online Store > Themes.
  2. Locate your Debut theme and then click Actions > Edit code.
  3. In the folder, open your theme.scss.liquid file.

    03-39-badae-sysyp
  4. Go to the very bottom of this file and paste the following code:

    #SearchDrawer {
      z-index:1001;
    }
    
    .site-header {
      position: fixed;
      z-index:1000;
      left:0;
      right:0;
      -webkit-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      -moz-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      -ms-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      -o-box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
      box-shadow:0px 2px 4px 0px rgba(0,0,0,.1);
    }
    
    #PageContainer {
      padding-top: 80px;
    }
    
    @media screen and (max-width: 749px) {
    #PageContainer {
      padding-top: 70px;
    }
    }
    
  5. In the same Assets folder, click to open your theme.js file.
  6. Go to the very bottom of this file and paste the following code:

    function headerSize() {
      var $headerHeight = $('div#shopify-section-header').outerHeight();
      $('#PageContainer').css('padding-top', $headerHeight);
    }
    
    $(window).on("load", headerSize);
    $(window).on("resize", $.debounce(500, headerSize));
    
    $(window).scroll(function() {
      scroll = $(window).scrollTop();
      if (scroll >= 1) {
        $('.site-header').css('top', '0');
      } else {
        $('.site-header').css('top', 'initial');
      }
    });
    
  7. Ensure that the code was copied exactly from this guide and pasted correctly, making sure no characters or symbols are missing.
  8. Save the file by using the button on the top right-hand side.
  9. Refresh your online store page and verify that the sticky header is working correctly!
Replies 153 (153)
diego_ezfy
Shopify Partner
2754 516 696

Hey everyone,

I have coded a professional, highly tested solution for this as well if you'd like to try.

You can download/install it for free under 1 minute, just click here to read the tutorial.

Besides that you also have options to turn it on/off at the customize page, even to allow it only on desktop or mobile depending on your needs.

Kind regards,
Diego

SportClothing
New Member
3 0 0

Hi. After installing several applications, such a message appeared on my website.
Does anyone know how to remove it? It's under the URL bar and the Menu bar in the center is gone. Thank youIMG_20210108_193615.jpg

birgitt
New Member
1 0 1

Hi there! 

I followed option 1 to add the sticky header, but I need to temporarily stop using the sticky header. When I comment out all the code I added for the sticky header in the theme.js and theme.scss.liquid and save, the header is still sticky on the published website. Would you kindly let me know what else I may need to do to remove the sticky header?

Thanks so much!

rip2
New Member
1 0 0

Thanks Diego, the free version works well for me. There are a few small bugs like resetting to the top of the page when you click the search icon in the menu bar, but these are very minor. Overall an easy copy & paste solution!

nezi
Tourist
6 0 3

Hi,

I added the Part 2 of the code given in the original post. The navigation menu is sticking and the announcement bar moves but as you scroll it shows the background above the navigation menu instead of the navigation moving up and replacing the announce

Screen Shot 2021-01-20 at 12.18.06 PM.png

ment bar. See photo.

topkozuchy
Tourist
3 0 0

Same problem for me 😞 

my website is topkozuchy.sk please if you could fix the space and moving menu bar to the top after scolling down it would help me. 

diego_ezfy
Shopify Partner
2754 516 696

@topkozuchy 

Have you checked this solution yet? It fixes the problem you mention. 

mywebsite1
Tourist
5 0 1

its not working for me

Blogbaba
tantsteven
New Member
2 0 0

06-Oct-2020 — The sticky header must contain the navigation as well. ... Making the menu fixed means that your navigation will always be fixed to the top of the ... I'll do the integration on the Debut theme which at this time is the default ...

jhonmusk12
New Member
2 0 0

Same problem for me 😞 

jhonmusk12
New Member
2 0 0

Same problem for me 😞 

emelineno
New Member
1 0 0

I have managed to fix it with option 1 (but only on desktop).

At first I got a delay on the top of each page, but I changed the padding top to 226px instead of 80px.

I looks fine on desktop, but on mobile it is still a delay. Can anyone help?

AustinK
New Member
3 0 0

@emelineno 

Iwas dealing with the same issue. gave up trying and paid $15 for some dev here to get it fixed for me. these things should be done automatically by shopify.....

rahulmittal79
New Member
3 0 0
I do have a little problem though.... after I scroll down the page and then back to the top, the top bar covers the content underneath it.
kwaris
Tourist
7 0 0
diego_ezfy
Shopify Partner
2754 516 696

@kwaris @AustinK @rahulmittal79 

You may want to give a try to this solution if you're still having trouble with it. 

Kind regards,
Diego

pogiroheat
New Member
1 0 0

Caution This is an advanced tutorial and is not supported by Shopify .

zeffire
New Member
2 0 1

zeffire_0-1614236967641.png

Hi I followed option 2. I have my announcement enabled. However when I scroll down, there is an awkward empty gap where the announcement banner should have been. I only want my menu bar to be sticky. Can someone please help to assist? Thank you

Nancy023
Tourist
3 0 1

Hi,
Very nice article.
I really enjoyed going through all the great information you’ve provided in this great article.
Keep up the great work.
Thank you

Craftbierbox
Tourist
11 1 0

Hi Sean or anyone who can help.

Thanks for the detailed solution, which is very helpful...and now comes the however. I cannot find the under Assets mentioned file /theme.scss.liquid
I've looked at other posts and found out that the file may be named css.theme (no s at the beginning and no .liquid at the end)  and accordong to the authors, that should also do the job.
So I pasted the code at the bottom of the file and then the second block of code in the Assets theme.js. file and it still doesn't work. I've made sure the Logo is aligned left before atarting the c.n.p action.

Any suggestion?

Thanks

Neil

 

UPDATE ...I read on until I found a suggestion from  Silverclouding Shopify Expert. This seems to have solved the issues. So thanks and I'll close this message

Regards

85 14 21