CMS Development

vorellana814
Member

Sticky Navigation Not Working!

SOLVE

Hey guys, I'm trying to create a sticky navigation with a hello bar on top. I want the hello bar to be out of view once you scroll and keep the navigation menu to the top. I did top: -32px so that the hello bar can be out of view. I tried it out in the module preview and it works but once it is on an actual page, position:sticky doesn't work. Can someone please help? I've been stuck on this! Here is my HTML and CSS. 

 

HTML:

<div class="nav-1">
<div class="mission-control-login-div">
<div class="hellobar">
<section class="mission-control-login">
<a href="">
<img src='{{ module_asset_url("test.svg") }}' width="20px" alt=""/>Testing
</a>
</section>
</div>
</div>
<div class="nav-2">
<nav class="menu menu--desktop" aria-label="Main menu">
<section>
<a href="/">
<img src="{{ site_settings.logoSrc }}" alt="" width="150px"/>
</a>
</section>
<ul class="menu__wrapper no-list">
{{ menu_items() }}</ul>
</nav>
</div>
</div>

 

CSS:

.nav-1 {
position: sticky;
left: 0;
top: -32px;
right: 0;
bottom: auto;
z-index: 999;
display: flex;
max-width: 100%;
margin-top: 0;
padding-top: 0;
flex-direction: column;
justify-content: space-between;
flex-wrap: nowrap;
align-items: center;
align-self: stretch;
order: 0;
flex: 0 auto;
border-bottom: 1px solid #efefef;
background-color: #fff;
box-shadow: 0 4px 3px 0 rgba(0,0,0,.05);
}

 

.mission-control-login-div {
width: 100%;
position: relative;
}

 

.nav-2 {
width: 100%;
position: relative;
}

0 Upvotes
1 Accepted solution
ankitparmar09
Solution
Top Contributor

Sticky Navigation Not Working!

SOLVE

Use this following css it will be work

 

.nav-1 {

   position: fixed;
  top: 0;
  width: 100%;
  z-index: 9999;

}

View solution in original post

2 Replies 2
ankitparmar09
Solution
Top Contributor

Sticky Navigation Not Working!

SOLVE

Use this following css it will be work

 

.nav-1 {

   position: fixed;
  top: 0;
  width: 100%;
  z-index: 9999;

}

piersg
Key Advisor

Sticky Navigation Not Working!

SOLVE

Can you link a page where you're having this issue please? It's much easier to diagnose and fix CSS when you can see and interact with it 🙂

0 Upvotes