Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my bootstrap navbar not displaying inline?

Here is my html using bootstrap (I'm sure bootstrap is installed correctly)

<nav class="navbar navbar-inverse">
    <div class="container-fluid">

        <div class="navbar-header">
            <a class="navbar-brand">Rebar</a>
        </div>

        <div>
            <ul class="nav navbar-nav">
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
                <li><a href="#">Link</a></li>
            </ul>
        </div>
    </div>
</nav>

When it displays the three links are being displayed as block elements.

like image 904
Nash Avatar asked May 21 '15 05:05

Nash


People also ask

Why is my navbar not horizontal?

You need to add display: inline; to the li elements to make them go horizontal. Save this answer.

Why is my navbar not working HTML?

The most common cause of links in the Navigation Bar being broken is a change to the Domain Name, Folder Name, or Domain Mapping. Links in the Navigation Bar and Blog Footer will not automatically update with changes to the URLs for your blog's content.

What is a collapsed navbar?

The navbar-collapse refers to the menu that is in the mobile view with the navbar (contains links, and toggle-friendly content). They are in the bootstrap CSS (see here). See this for a full rundown of how the navbar and collapse work together.

How do I float a navbar link to the right?

ml-auto class in Bootstrap can be used to align navbar items to the right. The . ml-auto class automatically aligns elements to the right.


1 Answers

This is because in Bootstrap the css for li is this:

.nav>li {
  position: relative;
  display: block;
}

But for me the menu seems to appear correctly. See snippet, but only on a full page. On mobile devices it will behave like a block element since the screen doesn't have room to show them inline.

EDIT: Updated the snippit to work as requested (see comments below this answer)

.navbar .container-fluid>.navbar-header {
  float: left;
  margin-right: 10px;
}
.navbar .navbar-nav {
  float: left;
  margin: 5px;
}
.nav>li {
  float: left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
  <div class="container-fluid">

    <div class="navbar-header">
      <a class="navbar-brand">Rebar</a>
    </div>

    <div style="display: inline-block;">
      <ul class="nav navbar-nav">
        <li><a href="#">Link</a>
        </li>
        <li><a href="#">Link</a>
        </li>
        <li><a href="#">Link</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
like image 150
Thomas Theunen Avatar answered Oct 23 '22 03:10

Thomas Theunen