Navbar scrollbar does not appear on another width

Asked

Viewed 548 times

4

I used the code below to change when the menu button for mobile is displayed and it worked, but the scroll bar does not appear in this size. What can I do to display the scroll bar? If I need to put images.

@media (max-width: 991px) {
    .navbar-header {
        float: none;
    }
    .navbar-toggle {
        display: block;
    }
    .navbar-collapse {
        border-top: 1px solid transparent;
        box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
    }
    .navbar-collapse.collapse {
        display: none!important;
    }
    .navbar-collapse.collapse.in {
        display: block!important;
    }
    .navbar-nav {
        float: none!important;
        margin: 7.5px -15px;
    }
    .navbar-nav>li {
        float: none;
    }
    .navbar-nav>li>a {
        padding-top: 10px;
        padding-bottom: 10px;
    }
} 

UPDATED:

Fiddle: https://jsfiddle.net/c80tn7qh/1/

Imagery:

Sem a barra de rolagem

Com a barra de rolagem

  • I don’t know how you are navbar, but try to put in the .navbar-headerone overflow: auto or overflow: visible.

  • I did the test, it didn’t work. I’ll put the navbar code and the prints. Thanks!

  • 1

    You can ride a Fiddle ?

  • Yes. Fiddle: https://jsfiddle.net/c80tn7qh/1/

  • places the first parent element of the items listed as Absolute, and his father gives you the overflow

  • I guess I still don’t understand what you need.

  • @Zooboomafoo increases window drop, items bounce out and does not display scrollbar.

  • 1

    @Murilogambôa looks like it worked, but when the menu finishes loading it disappears and displays all the items. I put overflow-y: scroll in DIV and position: absolute in the UL.

  • 2

    See if this is what you need ? https://jsfiddle.net/c80tn7qh/3/

  • 1

    @Zooboomafoo it! Just need to display some items only and display the bar to view others

  • 2

    So ? https://jsfiddle.net/c80tn7qh/4/

  • It worked out my suggestion ?

  • @Zooboomafoo this, it did! I went for a test and saw that the normal behavior of the navbar is to push the content down (it gets better), I did something that changed that, so I thought I’d use scrollbar. Anyway, it solved the problem, just add .navbar-header {float: none;}. Thank you.

  • I’ll post with the answer.

Show 9 more comments

2 answers

3

Usually to "force" the scroll bar is used overflow on target. Example:

body {
  overflow-x: scroll; // somente para horizontal
  overflow-y: scroll; // somente para vertical
  overflow: scroll; // horizontal e vertical
}

It can be applied to specific elements as well, such as div or styles.

Syntax:

overflow: Visible|Hidden|scroll|auto|initial|inherit;

  • The menu bar that does not appear, I did not specify right. I did a test by placing on . navbar-Nav and displayed only the bar without the "button" to drag, but the items stay out. I will put the prints to get better. Thanks!

2


@media (max-width: 991px) {
  .navbar{
    overflow: auto;
  }
      
        .navbar-toggle {
            display: block;
        }
        .navbar-collapse {
            border-top: 1px solid transparent;
            box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
        }
        .navbar-collapse.collapse {
            display: none!important;
        }
        .navbar-collapse.collapse.in {
            display: block!important;
        }
        .navbar-nav {
            float: none!important;
            margin: 7.5px -15px;
            overflow: auto;
        }
        .navbar-nav>li {
            float: none;
        }
        .navbar-nav>li>a {
            padding-top: 10px;
            padding-bottom: 10px;
        }
    } 
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
      <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" style="padding: 0; padding-top: 10px" href="index.php"></a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">SOBRE</a></li>
                <li><a href="#">PRODUTOS</a></li>
                <li><a href="#">SERVIÇOS</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li><a href="#">TESTE</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">CONTEÚDOS</a>
                    <ul class="dropdown-menu">
                        <li><a href="#">DA PESQUISA À INOVAÇÃO</a></li>
                        <li><a href="#">IMPRENSA</a></li>
                        <li><a href="#">EXCLUSIVO</a></li>
                    </ul>
                </li>
              <li><a href="#">CONTATO</a></li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.