I’m trying to make a sticky navbar so that when I scroll down I want my logo, my search bar, sign in button and my navbar scroll down as well.
The problem is that when I’m scrolling down, my logo and nav bar go behind my slideshow; they do not show and they’re also transparent. I’m working on it for 2 days now but couldn’t figure it out.
div#shopify-section-header {
position: fixed;
background-color: black;
}
<div id="shopify-section-header" class="shopify-section header-section">
<header class="site-header" role="banner" data-section-id="header" data-section-type="header-section">
<div class="wrapper">
<div class="grid--full">
<div class="grid-item large--one-half">
<h1 class="header-logo" itemscope="" itemtype="http://schema.org/Organization">
<a href="/" itemprop="url">
<img src="//cdn.shopify.com/s/files/_tagline_bpng?v=1512661427" srcset="//tagline_black_whitebkg_250x.png?v=1512661427 1x, //cdn.shopify.com/s/files/1/2045/6673/files/[email protected]?v=1512661427 2x"
alt="test" itemprop="logo">
</a>
</h1>
<div class="clearfix"></div>
<a class="contact-header-logo" href="/pages/contact-us">Contact Us</a>
</div>
<div class="grid-item large--one-half text-center large--text-right">
<div class="site-header--text-links medium-down--hide">
<div id="ly-languages-switcher">
<a href="#" id="ly40221" class="ly-languages-switcher-link current_lang">English</a>
<span>/</span>
<a href="#" id="ly40222" class="ly-languages-switcher-link">Français</a>
</div>
<div class="currencyRobo medium-down--hide">
<div class="currencyRoboSelect">
<select class="currencyRoboSelectBox" name="currencyRoboSelect">
<option value="CAD">CAD</option>
<option value="CHF">CHF</option>
<option value="EUR">EUR</option>
<option value="GBP">GBP</option>
<option value="USD">USD</option>
</select>
</div>
</div>
<span class="site-header--meta-links medium-down--hide">
<a href="/account/login" id="customer_login_link">Sign in</a>
<span class="site-header--spacer">or</span>
<a href="/account/register" id="customer_register_link">Create an Account</a>
</span>
</div>
<br class="medium-down--hide">
<form action="/pages/search-results" method="get" class="search-bar" role="search">
<input type="hidden" name="type" value="product">
<input type="search" name="q" value="" placeholder="Search all products..." aria-label="Search all products..." class="stop-mega-menu-reinit" autocomplete="OfF" id="_ispbxii_0" autocorrect="off" autocapitalize="off">
<button type="submit" class="search-bar--submit icon-fallback-text">
<span class="icon icon-search" aria-hidden="true"></span>
<span class="fallback-text">Search</span>
</button>
</form>
<a href="/cart" class="header-cart-btn">
<span class="icon icon-cart"></span> Cart <span class="cart-count cart-badge--desktop hidden-count">0</span>
</a>
</div>
</div>
</div>
</header>
<nav class="nav-bar sticky-header" role="navigation">
<div class="wrapper">
<form action="/pages/search-results" method="get" class="search-bar" role="search">
<input type="hidden" name="type" value="product">
<input type="search" name="q" value="" placeholder="Search all products..." aria-label="Search all products..." class="stop-mega-menu-reinit" autocomplete="OfF" id="_ispbxii_1" autocorrect="off" autocapitalize="off">
<button type="submit" class="search-bar--submit icon-fallback-text">
<span class="icon icon-search" aria-hidden="true"></span>
<span class="fallback-text">Search</span>
</button>
</form>
</div>
</nav>
</div>
3
Answers
After seeing your live code, I have added this and tested it:
Check this Fiddle. There are a couple of issues in your HTML, like your wrapping DIV is not closed. First try to fix the HTML, then add CSS to position your sticky DIVs separately.
HTML:
CSS:
Play around in this fiddle: https://jsfiddle.net/sztkujb2/10/
The
code snippet
doesn’t contain all the resources and it’s hard to understand the environment in which thenavbar
is used. This is a important detail and its very useful for developers.Today, I don’t have anymore time to continue. I plan to update my answer or maybe other developers will continue from where I left.
My approach for a solution is:
Notes:
a) A sticky nav is already used, on large screens it display but only for the the menu elements. I think the request is to make the entire nav bar sticky.
b) A solution is necessary for only for large screens(desktops), making the entire nav sticky
1) Clone current HTML nav structure and append it after/before the original nav. Without this, after the original nav is sticky(
position: fixed
), the content will go upwards.2) After scroll certain distance, add a
CSS class
to the orignalnav
with sticky rules. (#style #UX) I would decrease size of certain elements in order to leave more visible space.3) Show(
visibility : hidden
) the cloned nav structure.Current code: