David Moreno García
David Moreno García

Reputation: 4523

Pull dropdown to the left when Bootstrap navbar is collapsed

I'm using Bootstrap 3 in an app dashboard and I'm facing a problem using navbar. I added a dropdown menu that is being shown correctly, but once I resize the window and the navbar is collapsed, it is showed at the left instead that at the right. What can I do to solve it?

Here you can find an screenshot with the problem and what I need, and some code:

enter image description here

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse"
        data-target=".navbar-collapse">
        <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" href="#">Dashboard</a>
</div>

<c:if test="${not empty username}">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown"><a href="#" class="dropdown-toggle"
                data-toggle="dropdown">${username} <span
                    class="glyphicon glyphicon-user"></span><b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li><a href="<c:url value='/logout' />">Logout</a></li>
                </ul></li>
        </ul>
    </div>
</c:if>

Upvotes: 1

Views: 6411

Answers (1)

Schmalzy
Schmalzy

Reputation: 17324

The navbar collapses at 768px, so this media query will float your navbar-nav to the right once the navbar is collapsed.

Here is a jsFiddle Demo

CSS

@media (max-width: 768px){
    .navbar-nav{
        text-align: right;
    }
}

Upvotes: 2

Related Questions