materialize icon indicating copy to clipboard operation
materialize copied to clipboard

Cant use a slideNav with a fixed navbar

Open jakewhiteley opened this issue 11 years ago • 7 comments

If you have a top navigation bar with a class of .navbar-fixed, then any sideNavs within that navbar, will render underneath the overlay in Chrome 39.

No matter what z-index you set on the sideNav, it wont display higher than it's fixed parent. This makes it unusable - as any attempt to click a link, triggers the event to dismiss the sideNav.

sidenav-issue

jakewhiteley avatar Jan 11 '15 23:01 jakewhiteley

It was briefly discussed in issue https://github.com/Dogfalo/materialize/issues/393 after it was closed (the main issue was different). There are some tips there about z-indexing, but I believe this is still not working correctly.

carlosperate avatar Jan 11 '15 23:01 carlosperate

With a bit of fiddling with css, it is possible to make a sideNav work if it is a child of a non fixed element.

In the above image, the cart icon on the right triggers a separate sideNav from the right. As this is included in the footer on my page, the sideNav slides in at the correct z-index.

sidenav-issue

To fix this for normal navigation without changing the required markup, I would suggest modifying sideNav.js to create <div id="sidenav-overlay"></div> as the first direct child of the parent <nav> element, instead of before the end body tag.

This way the result is as expected.

sidenav-issue

jakewhiteley avatar Jan 12 '15 00:01 jakewhiteley

The following would work in js/sideNav.js:

Add this to line 54

var navbarFixed = $('.navbar-fixed nav');

Change lines 122 and 200

if (navbarFixed.length > 0)
    navbarFixed.prepend(overlay);
else
    $('body').append(overlay);

jakewhiteley avatar Jan 12 '15 01:01 jakewhiteley

Should be fixed in 0.95

acburst avatar Jan 21 '15 22:01 acburst

I just figured out the solution. Instead of this: <div class="navbar-fixed"> ... <a href="#" data-activates="slide-out" class="button-collapse">...</a> <ul id="slide-out"> ... </ul> </div> do this:

<div class="navbar-fixed"> ... <a href="#" data-activates="slide-out" class="button-collapse">...</a> </div> <ul id="slide-out"> ... </ul>

Why? While the slide-out is inside the navbar-fixed-classed element the browser ignores it's z-index rule so sidenav-overlay shades it as a navbar-fixed's child div. By placing it outside your fixed element everything works normally. Hope that helped some and sorry for any mistakes on this post I just signed up here...

MindRapist avatar Feb 09 '17 19:02 MindRapist

This just fixed my problem.

<!-- HTML-->
<div class="navbar-fixed>
       <nav>
            <div class="nav-wrapper">
                <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
                <ul class="right hide-on-med-and-down">
                    <li><a class="waves-effect waves-light" href="#header">Intro</a></li>
                                                               . . . . 
                    <li><a class="waves-effect waves-light" href="#blog">Blog</a></li>
                </ul>
                <ul class="side-nav" id="mobile-demo">
                    <li><a href="#header">Intro</a></li>
                                            . . . . .
                    <li><a href="#blog">Blog</a></li>
                </ul>
            </div>
        </nav>
</div>

<!--CSS-->
.navbar-fixed{
    z-index: 1000;
}

SunilDSK avatar Mar 29 '17 08:03 SunilDSK

These issues are all duplicates: https://github.com/Dogfalo/materialize/issues/1664 https://github.com/Dogfalo/materialize/issues/3918 https://github.com/Dogfalo/materialize/issues/4046 https://github.com/Dogfalo/materialize/issues/4231 https://github.com/Dogfalo/materialize/issues/437 https://github.com/Dogfalo/materialize/issues/4318 https://github.com/Dogfalo/materialize/issues/3982 https://github.com/Dogfalo/materialize/issues/2879 https://github.com/Dogfalo/materialize/issues/4187

For the future discussion, please use this issue instead. https://github.com/Dogfalo/materialize/issues/3844

tomscholz avatar Apr 01 '17 12:04 tomscholz