Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap 3: right aligned collapsing nav issue

Using Twitter Bootstrap 3.

I have a fixed navbar with the menu items aligned to the right by adding .pull-right to the ul inside the navbar-collapse div.

When the nav collapses on small screens and you click to open it, the nav items are not 100% width as they should be, but about 30% and pulled to the right.

Have fixed this with:

@media (max-width: 767px) { 
    .navbar-nav.pull-right { float: none!important; }
}

But wondering if there is a better way to do it.

Code for the navbar is:

<!-- Fixed navbar -->
<div class="navbar navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">
                <img src="application/assets/img/main-logo.png" alt="">
            </a>
        </div>
        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav pull-right">
                <li class="active"><a href="#">Menu 1</a></li>
                <li><a href="#about">Menu 2</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu 3 <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li class="divider"></li>
                        <li class="dropdown-header">Nav header</li>
                        <li><a href="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu 4 <b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li>
                        <li><a href="#">Another action</a></li>
                        <li><a href="#">Something else here</a></li>
                        <li class="divider"></li>
                        <li class="dropdown-header">Nav header</li>
                        <li><a href="#">Separated link</a></li>
                        <li><a href="#">One more separated link</a></li>
                    </ul>
                </li>
                <li><a href="#about">Menu 5</a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</div>
like image 990
Leon Avatar asked Sep 19 '13 10:09

Leon


1 Answers

I read the manual!!

Need to use .navbar-right instead of .pull-right which has the media query already built in to bootstrap.

like image 171
Leon Avatar answered Sep 28 '22 08:09

Leon