Jump to content

Sticky navigation on one page only — z-index not working

Recommended Posts

Hi all, I'm building a page with a long scrolling story and wanted to add a sticky navigation menu to this page ONLY, to help readers with navigation.

I found a way to do it (thanks to this post by Inscape Web Design) and at first it was working beautifully, but I must have changed something by accident because now the z-index is not working, and once you scroll past the section where the code block lives, other elements on the page show up ON TOP of the sticky navigation menu (they need to be beneath/behind it to keep the navigation visible/clickable).

Here is the code I am using for the sticky navigation menu:

--

<style>
#special-nav > div{padding-right:20px}
  #special-nav > div:last-child{padding-right:50px}
#special-nav {
  position:fixed!important;
  z-index:9999!important;
  display:none;
  flex-direction:row;
  flex-wrap:wrap;
  justify-content:flex-end;
  background-color:transparent;
  background-image: url("https://static1.squarespace.com/static/61e1c0b727dbad5f635ac8af/t/6398eece2768bf74e80761a2/1670966993723/organic-gradient-bg.png");
  background-repeat: repeat;
  background-position: center;
  background-size: cover;
  opacity:1.0;
  padding:12px 12px 12px 12px;
  width:100%;
  top:64px;
  left:0px;
  box-shadow: 4px 4px 7px rgba(0,0,0,0.4)
  }
  #special-nav h3 {
  color:white !important;
  font-size:13px;
  }
  
  #special-nav h3 a{
  color:white !important;
  font-size:13px!important;
  font-weight:400!important;
  border-bottom-color:white !important;
    }
  #special-nav a:hover{color:white !important; opacity:0.6;}
  
@media screen and (max-width: 640px) {
  #special-nav {display:none !important;}}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
 $(document).on('scroll', function() {
   if ($(document).scrollTop() >= 100) {
     $('#special-nav').css('display', 'flex');
   } else {
     $('#special-nav').css('display', 'none');
   }
 });
 </script>

<div id="special-nav">
    <div><h3>2022 | Our Year in Review</h3></div>
    <div><h3><a href="/2022-test#intro">Intro</a></h3></div>  
    <div><h3><a href="/2022-test#build-networks">Building Networks</a></h3></div>
    <div><h3><a href="/2022-test#change-policies">Changing Policies</a></h3></div>
    <div><h3><a href="/2022-test#shift-culture">Shifting Culture</a></h3></div>
    <div><h3><a href="/2022-test#increase-capacity">Increasing Capacity</a></h3></div>
  <div><h3><a href="/2022-test#nurture-org-health">Nurturing Our Organization's Health</a></h3></div>
</div>

--

I'm not a web designer or developer by any means, have only played around with html and css here and there on my own and cobbled things together. Also this is my first time posting in the forum. Would love some help figuring this out!

Edited by margaret-squarespace
Link to comment
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

13 hours ago, margaret-squarespace said:

Hi all, I'm building a page with a long scrolling story and wanted to add a sticky navigation menu to this page ONLY, to help readers with navigation.

I found a way to do it (thanks to this post by Inscape Web Design) and at first it was working beautifully, but I must have changed something by accident because now the z-index is not working, and once you scroll past the section where the code block lives, other elements on the page show up ON TOP of the sticky navigation menu (they need to be beneath/behind it to keep the navigation visible/clickable).

Here is the code I am using for the sticky navigation menu:

--

<style>
#special-nav > div{padding-right:20px}
  #special-nav > div:last-child{padding-right:50px}
#special-nav {
  position:fixed!important;
  z-index:9999!important;
  display:none;
  flex-direction:row;
  flex-wrap:wrap;
  justify-content:flex-end;
  background-color:transparent;
  background-image: url("https://static1.squarespace.com/static/61e1c0b727dbad5f635ac8af/t/6398eece2768bf74e80761a2/1670966993723/organic-gradient-bg.png");
  background-repeat: repeat;
  background-position: center;
  background-size: cover;
  opacity:1.0;
  padding:12px 12px 12px 12px;
  width:100%;
  top:64px;
  left:0px;
  box-shadow: 4px 4px 7px rgba(0,0,0,0.4)
  }
  #special-nav h3 {
  color:white !important;
  font-size:13px;
  }
  
  #special-nav h3 a{
  color:white !important;
  font-size:13px!important;
  font-weight:400!important;
  border-bottom-color:white !important;
    }
  #special-nav a:hover{color:white !important; opacity:0.6;}
  
@media screen and (max-width: 640px) {
  #special-nav {display:none !important;}}
</style>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
 $(document).on('scroll', function() {
   if ($(document).scrollTop() >= 100) {
     $('#special-nav').css('display', 'flex');
   } else {
     $('#special-nav').css('display', 'none');
   }
 });
 </script>

<div id="special-nav">
    <div><h3>2022 | Our Year in Review</h3></div>
    <div><h3><a href="/2022-test#intro">Intro</a></h3></div>  
    <div><h3><a href="/2022-test#build-networks">Building Networks</a></h3></div>
    <div><h3><a href="/2022-test#change-policies">Changing Policies</a></h3></div>
    <div><h3><a href="/2022-test#shift-culture">Shifting Culture</a></h3></div>
    <div><h3><a href="/2022-test#increase-capacity">Increasing Capacity</a></h3></div>
  <div><h3><a href="/2022-test#nurture-org-health">Nurturing Our Organization's Health</a></h3></div>
</div>

--

I'm not a web designer or developer by any means, have only played around with html and css here and there on my own and cobbled things together. Also this is my first time posting in the forum. Would love some help figuring this out!

Can you check your URL again?

image.thumb.png.b498ac4c03916ce39c969db8fd9a6695.png

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Keyword Highlighter
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment
On 12/16/2022 at 2:20 AM, margaret-squarespace said:

Sorry I updated the URL!

https://www.sdfsa.org/2022

Don't remove any code in your current code.

Add this to Design > Custom CSS

section[id*="2022/intro"] {
    z-index: 99999;
}

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.