question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Top title not correctly centered because width of 'navbar fixed nav' is too large

See original GitHub issue

Hi,

With a viewport width greater than 992 pixels, my left pane is fixed and always visible. In this case, the title on my fixed top navbar is not correctly centered (see html code below)

This is due to the fact that the width of ‘navbar-fixed .nav’ is 240 px too large : fixed positionning causing width to be 100% of the viewport instead of 100% of the ‘parent’ (header)

I fixed this by adding this in the css:

.navbar-fixed nav { 
    position: fixed; 
    /* width is 100% minus the fixed left navbar (240px) */
    width: -moz-calc(100% - 240px); /* Firefox */
    width: -webkit-calc(100% - 240px); /* Chrome, Safari */
    width: calc(100% - 240px); /* IE9+ and future browsers */
} 

@media only screen and (max-width : 992px) {
/* width is 100% because the fixed left navbar is not displayed */
    .navbar-fixed nav { width: 100% }
}

my html page (with materialize.css 0.96.0) looks like

[...]
        <header>
            <div class="navbar-fixed">
                <nav>
                    <div class="nav-wrapper">
                        <a id="top_title" href="#!" class="brand-logo center">My Title</a>
                        <a href="#" data-activates="nav-mobile" class="button-collapse"><i class="mdi-navigation-menu"></i></a>
                    </div>
                </nav>
            </div>

            <ul id="nav-mobile" class="side-nav fixed">
                <li class="logo" style="height:120px; padding: 25px 15px">
                    <a id="logo-container" href="#">
                        <object id="front-page-logo" type="image/svg+xml" data="logo.svg">Your browser does not support SVG</object></a></li>
            </ul>
        </header>
       <main>
[...]

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
transpirmancommented, Apr 16, 2015

Sorry for lacking additional info: actually, I used a fixed side nav as described at the bottom of the page http://materializecss.com/side-nav.html

=> when you add left padding of 240 px to the header, the fixed div at the top (nav bar) keeps the same width which makes it goes beyond the right border of the screen. So you need also to add the css code I described before.

Best Regards, and really great work of your team !!

PS: I am not too familiar with creation of codepen… I will try to illustrate that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

top nav bar blocking top content of the page - Stack Overflow
For bootstrap 3, the class navbar-static-top instead of navbar-fixed-top prevents this issue, unless you need the navbar to always be visible.
Read more >
Header - W3Schools Tryit Editor
<title>CSS Website Layout</title> ... <meta name="viewport" content="width=device-width, initial-scale=1"> <style> ... Style the top navigation bar */
Read more >
Navbar · Bootstrap v5.1
Navbars and their contents are fluid by default. Change the container to limit their horizontal width in different ways. Use our spacing and...
Read more >
Bootstrap Navbar - examples & tutorial
Examples with logo, dropdown, collapse, sticky header, toolbar, search bar in nav & hamburger icon. Align to the left, right or center. Fixed...
Read more >
Can't get nav-bar to align right - The freeCodeCamp Forum
The problem is it's responsiveness, try to make so it resizes correctly to smaller screens by using media queries or %, vw, vw,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found