Avoid having the navigation bar menu wrap over onto multiple lines

While using Bootstrap to create a navbar and resizing the browser window to a smaller width, you may notice that the menu items wrap onto multiple lines:

How can we prevent the menu items from wrapping and keep them on a single line? (the buttons/search field should stack above the brand logo, potentially hiding the brand)


Below is the code for the navbar:

<nav class="navbar navbar-default">
    <div class="container-fluid">
      <div class="navbar-header">
        <a class="navbar-brand" href="#">Brand</a>
      </div>
      <div>
       <ul class="nav navbar-nav navbar-right">
        <li class="navbar-form">
            <div class="form-group">
              <div class="input-group input-group-sm">
                    <input class="form-control" placeholder="Search" type="text">
                    <span class="input-group-btn">
                      <button class="btn btn-default" type="button"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
                    </span>
              </div>
            </div></li>
          <li><a type="button" class="btn btn-default btn-sm" href="http://gget.it/ornlbhjq/edit.php" id="newpost">New post</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle btn btn-default btn-sm" data-toggle="dropdown" role="button" aria-expanded="false" id="dropdown">Login / Signup&nbsp;<span class="caret"></span></a>
            <ul class="dropdown-menu" role="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><a href="#">Separated link</a></li>
            </ul>
          </li>
        </ul>
      </div>
    </div>
  </nav>

Answer №1

The reason for the issue is that the list items in .navigation are set to have a display:block;, which automatically takes up all available space.

To fix this problem, you can update the code from:

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

To:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The CSS3 Animation-fill-mode: An Essential Property

I am working on a cool effect where text slides into the window and remains in place after the animation is complete. Surprisingly, I have managed to get the animation to work on one part of the text, but for some reason, the second part is not cooperating ...

Gradient background overlaid with a blended SVG shape

Creating a full gradient background with a clipping mask can be tricky. I used an SVG to achieve the desired shape by cutting part of the background color, but now I'm facing a challenge with blending the colors seamlessly. I tried setting the SVG co ...

Checkbox customization that shifts position when clicked

I seem to be missing something as I can't seem to find a solution for this particular issue. I have implemented custom checkboxes on a list of sentences. Initially, they appear fine, but once you check the first checkbox, it shifts its position. I am ...

Optimizing CSS for printing with margins and overflow

After stumbling upon a helpful solution here, I wanted to print small cage cards in a neat format with some tweaks of my own. Currently, this is how it appears for me (Fiddle): /* CSS styles */ (styles modified here) * { -moz-box-sizing: border-b ...

What measures can be taken to stop LESS partials from compiling independently?

When working with LESS, I utilize partials that are included (@include) into the main LESS stylesheet. A common issue I face is that each partial ends up compiling to its own CSS file, leading to project clutter. In SASS, if a file is named with an unders ...

Having trouble with Flowbite dropdown functionality in Next.js 12.* with Tailwind CSS

Hello, I am a newcomer to Next.js and currently working on a project using Tailwind/Flowbite. I copied and pasted the Flowbite search input with dropdown code from , but unfortunately, the dropdown is not functioning as expected. I have followed the docum ...

"Is there a way to determine the height of an inline element, such as a span element,

var mySpan=document.getElementById("mySpan"); alert(mySpan.height); <span id="mySpan" style="line-height:200px;">hello world</span> However, the result I receive is undefined. This is because Javascript can only retrieve the he ...

Leveraging Vue Data for Storing CSS Properties

I am currently utilizing the Quasar framework in conjunction with Vue for my application development. Below is a snippet of my code: <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"> Save </q-tooltip> <q-tooltip c ...

I am looking to incorporate a database field into a dropdown menu for use in a GET API request

page.ts retrieveData() { var url = 'http://hostname/databasename/.php'; var info = JSON.stringify({}); this.http.post(url, info).subscribe(response => { if (response == 0) { this.info = false; } e ...

Utilizing Reactstrap to design a customized vertical login page and NavBar with a unique background and text color scheme

I am currently working on creating a login page for accessing the main site that features a NavBar. I am utilizing ReactStrap, but I am facing challenges in making the NavBar vertical instead of horizontal, as well as customizing the background, text color ...

Exploring the latest features in Bootstrap 4 Alpha and enhancing your

Rumors have it that Bootstrap 4 will make its debut during the year 2016. When duty calls for an upgrade, is a complete re-write truly the best solution? Tackling such a project from Boostrap 2 to 3 was no small feat, and I find myself hesitant to take on ...

Tips for ensuring only one submenu is open at a time

I have successfully created a responsive menu that is working well. However, I am facing an issue. I want only one menu to be open at a time. When a submenu is opened, the other menus should be hidden. How can I achieve this? Below is my Script code $( ...

What is the best way to create rounded images in Bootstrap?

I'm having trouble achieving a perfect circle shape for my images using the following CSS code: .rounded { border-radius: 50px!important; } Even when I increase the border-radius to more than 50px, there is still a horizontal line at the top and ...

Is there a way to create distance between these icons?

<div id="unique-icons"> <a href="#"> <img class="github-logo1" src="GitHub-Mark-64px.png" alt="first github logo"> </a> <a href="#"> <i ...

What could be causing my CSS Grid to misbehave?

I am diving into the world of CSS Grid and attempting to create a sign-up page similar to that of Facebook. The layout I have in mind involves placing the first name and last name on one line, the email address on another line, and a submit button on a th ...

Scroll bar displayed on a non-editable text box

The TextArea is currently set to readonly mode using "ng-readonly," which is causing the scrollbar-thumb not to appear. It's important to note that I am not utilizing webkit in this scenario. Below is the HTML code being used: <textarea dataitemfq ...

Position the middle character within a span that has the identical width and height

My goal is to align characters in the center of a span. CSS span{border-radius:10px; width:20px; height:20px; color:#fff; background:#cc0000; text-align:center; line-height:20px; display:block;} HTML <span>+</span><br> <span>-&l ...

Height Mismatch in Nested Div Elements

How can I make the container div resize to fit its contents (content div)? I've tried but it doesn't seem to work. Here's an example in example.html: <html> <head> <link href="example.css" rel="stylesheet" type=" ...

The PNG image that is stored in the MySQL database is not displaying completely on the web browser

Here are the PHP codes from index.php <?php include("connection.php"); $sql = "SELECT prod_cost, prod_name, prod_image FROM products"; $result = mysqli_query($con, $sql); $row = mysqli_fetch_all($result, MYSQLI_ASSOC ...

Eliminate Bootstrap's validation glyphs

Issue Description I am attempting to eliminate the validation icons from Bootstrap, such as the "x" and "check" symbols. Despite my efforts to search thoroughly, I have been unable to locate where these icons are located in the code. Code Sample You can ...