Bootstrap navbar does not appear on smaller devices due to a display issue

This particular navigation bar, featuring a logo image in the center, functions well on larger screens. However, when viewed on smaller screens, everything disappears, including the logo image, and the hamburger menu icon fails to display. Is there a solution to this problem?

Check out the link for reference: http://codepen.io/davidcochran/pen/Fkwys

#navbar-primary .navbar-nav {
  width: 100%;
  text-align: center;
}
#navbar-primary .navbar-nav > li {
  display: inline-block;
  float: none;
}
#navbar-primary .navbar-nav > li > a {
  padding-left: 30px;
  padding-right: 30px;
}
<header role="banner">
<nav id="navbar-primary" class="navbar" role="navigation>
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->:
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-primary-collapse">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <div class="collapse navbar-collapse" id="navbar-primary-collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
        <li><a href="#"><img id="logo-navbar-middle" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/32877/logo-thing.png" width="200" alt="Logo Thing main logo"></a></li>
        <li><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
</header><!—header role=”banner” —>

Answer №1

Updated for the latest version in 2022

The Bootstrap 5 Navbar now requires the addition of either the navbar-light or navbar-dark classes to display the hamburger menu.

Original Solution

Although it is present, the lack of a background-color may be causing it not to appear.

To remedy this, use either the navbar-default navbar-light or navbar-dark class:

<nav id="navbar-primary" class="navbar navbar-light bg-light" role="navigation">

Alternatively, you can add a background color manually:

#navbar-primary .navbar-nav { 
   background: #ededed;
}

Or, darken the toggler icon:

.navbar-toggle .icon-bar {
    background-color: rgb(136, 136, 136);
}

Explore the live example on Codeply

Update for Bootstrap 4.0.0

The navbar-default class has been removed. Instead, opt for either navbar-light bg-light for a light navbar, or navbar-dark bg-dark for a darker navbar.


For more details, refer to: How to modify the color of the Bootstrap 4 navbar button icon?

Answer №2

Attention all Bootstrap users with Blazor Webassembly on Stack Overflow: I've solved a pesky problem that had been frustrating me to no end.

Initially, the navbar would display on a wide screen. But as I narrowed the screen, the hamburger menu button appeared. However, when I continued to make the screen narrower, the hamburger menu button mysteriously vanished.

The culprit turned out to be the default MainLayout.razor file and MainLayout.razor.css file that come with the Blazor Webassembly project template in Visual Studio. These files contained a media query that hid the menu below a certain breakpoint.

@media (max-width: 640.98px) {
    .top-row:not(.auth) {
        display: none;
    }

    .top-row.auth {
        justify-content: space-between;
    }

    .top-row a, .top-row .btn-link {
        margin-left: 0;
    }
}

After removing this query, everything now functions perfectly.

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

Struggling to figure out Visual Studio Code - Having trouble loading images and fonts into my CSS file

It seems like I'm missing something here (just so you know, I'm totally new at this). I attempted to use fonts that are loaded on my computer for my CSS stylesheet (font file in my VSC), but no luck. I also tried using images from my files as bac ...

Alter the CSS display based on the user's userAgent if they are using an iPhone and window.navigator.standalone is set to true

Looking to create a unique webAPP with different content displays based on how it is accessed. If the user opens the webAPP through their Safari browser Or if they open the webAPP from a webclip on their home screen The detection is functioning, as conf ...

Prevent a div from scrolling once it reaches the end of its content, while allowing the other div to continue

I am trying to make the col-md-4 column stop scrolling once it reaches the end of the content, similar to the right sidebar on Facebook. I have attempted using jQuery to add a fixed position when it reaches the bottom, but it is not working as expected. Th ...

Combine consecutive <p> tags within a <div> container

Can you group all adjacent <p> elements together within a <div> element? For example, assuming the following structure: <div class="content"> <p>one</p> <p>two</p> <h2> not p</h2> <p>thr ...

Ways to limit file types (such as .pdf) in HTML5?

What is the best method to limit file types (such as .pem, .cer) in HTML5? The accept attribute does not completely prevent users from uploading other file types. This particular input field is of type "file". ...

Inspecting the options within a dropdown menu to adjust a styling attribute

I am in the process of developing a website that features multiple select options for creating sentences. My goal is to detect when users are changing these options to form specific sentences, such as changing "I", "Am", "Blue" to reflect the color blue. T ...

Selecting menu items in React Material UI with various background colors using the RAL color selector component

Seeking a solution to create a component for selecting RAL colors using Material UI's TextField and MenuItem. Each item in the menu should have a background color reflecting the RAL color it represents. However, Material UI no longer supports inline s ...

Possible revision: "Trouble with event triggering when using an anchor tag within an <li> element

I am currently working with a horizontal menu plugin where I am including anchor tags within the <li> elements to create menu items. I have set up an onmouseover event for the anchor tag to display the submenu when the mouse hovers over it. However ...

Steering your pop up to the top with CSS

Seeking advice on how to position my pop-up at the top of the page and resize it to better fit the screen. Here is where you can find my landing page: yogavoga.com/2weekdiet Grateful for any assistance provided. .modal-content { margin: 5px auto; bac ...

Tips for stopping the background color from affecting the text color

I'm dealing with a situation where I have an h6 nested inside a div. <div class="cylinder" data-v-5147e140=""> <div data-v-5147e140=""> <h6 class="quantite" data-v-5147e140="&qu ...

Finding the dynamic width of a div using JavaScript

I have two divs named demo1 and demo2. I want the width of demo2 to automatically adjust when I drag demo1 left to right or right to left. <div class="wrapper"> <div class="demo"></div> <div class="demo2"&g ...

The jquery script for the dynamic remove button is malfunctioning

I have successfully implemented code to display dynamic controls using jQuery. Below is the working code: <script type="text/javascript"> $(document).ready(function() { $("input[value='Add']").click(function(e){ e. ...

What is the best way to add a data value to a dynamically generated div element?

I've been struggling to link a data value with a dynamically created div, but so far I haven't had any success. I've searched online for solutions, but I can't find any examples that fit my specific issue. If anyone has any advice, I wo ...

The jQuery click function triggers immediately upon the loading of the page

Despite my best efforts to resolve this issue independently and conduct extensive research on Google, I am still unable to identify the root of the problem. It seems that the click function continues to activate upon page load. Kindly elucidate the under ...

Error message in JS and HTML is totally bizarre

My expertise in JavaScript is very limited, so the terms I use might not be entirely accurate. However, I'll do my best to explain the issue at hand. I'm facing a peculiar problem... I've been attempting to modify someone else's JS scr ...

Example using three.js showing issues with external resources failing to load on jsfiddle.net

Currently, I am endeavoring to make progress with this sample project: github.com/josdirksen/learning-threejs/blob/master/chapter-09/07-first-person-camera.html I have made attempts at replicating the code on my personal pages.github.io account and also m ...

Create a concise shorthand representation for margins when styling with jss using Material-UI's theme object

When styling the component, I found a way to apply the margin in a specific manner. style.js const styles = theme => ({ button: { margin: '12px 18px', } }) However, I wanted to utilize material-ui's theme.spacing.unit f ...

Creating a sidebar that extends to the bottom of the webpage using

My friend is currently designing his website, and he has encountered an issue with the sidebar. He wishes for the sidebar to extend all the way down to the bottom of the page rather than just the visible portion within the browser window. You can view the ...

The nodes on a 2-dimensional grid overlap each other when the browser window is resized

In my project, I have set up a grid with 24 rows and 64 columns, totaling to 24x64 nodes. However, I am facing an issue where the nodes overlap when I open the console window. I am looking for a solution to automatically resize all nodes based on changes ...

Discover the method for storing multiple values in local storage using a dictionary with JavaScript

I have a scenario in my code where I need to update a value without storing a new one. Let's say I need to input values in the following format: { firstname:'kuldeep', lastname:- 'patel' } After entering the values, they g ...