How to center the navbar in Twitter Bootstrap when it switches to two rows in responsive mode

I am facing an issue with my navbar that has dropdowns. When the navbar is on a single row at full screen size, I have managed to center it. However, when the screen size is reduced and the navbar expands to two rows, neither row appears centered. How can this be resolved?

For reference, here is the jsFiddle link: http://jsfiddle.net/grzt/US2sS/

Feel free to adjust the frame size in the lower-right corner of the jsFiddle to see the different behavior based on screen size.

HTML:

<nav class="navbar navbar-inverse">
  <div class="container-fluid" style="text-align: center;">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-navbar-collapse" id="navigation-collapse-btn">
      <div id="navigation-collapse-text">Navigation</div>        
        <span class="sr-only">Toggle navigation</span>
      </button>

            <div class="collapse navbar-collapse" id="navigation-navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" style="padding-left: 0;">Some Words <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Link</a></li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Some Words <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Link</a></li>
                        </ul>
                    </li>
                    (Continues for more dropdown elements)
                </ul>
        </div>
  </div>
</nav>

<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

CSS:

.navbar-nav {
  /*center navbar inner elements*/    
  display: inline-block;
  float: none;
}

.navbar-toggle 
{
  /*center collapse button*/
  float:none;
}

Answer №1

To ensure your menu stays centered, it's best to avoid using float. Take a look at this for possible solutions.

@media (min-width: 768px) {
    .navbar-nav>li {
    float: none;
    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

Tips for sending a String[] to my Angular 2 HTML template

In the export class of my component, I have a string array variable declared like this; barChartLabel:string[] = ['2006', '2007', '2008', '2009', '2010', '2011', '2012']; To display t ...

Added the .active state to the menu navigation successfully, however the active color was not implemented

My primary navigation menu is managed by WordPress and can be seen below. I aimed to modify the active state when a user clicks on a link in the menu by adding background-color and color for styling purposes. Although changing the background-color upon cl ...

Can a Django form be configured to hide submitted values using display:none?

As I was working on submitting a form in Django with multiple details, I came up with the idea to split it into sections. The first set of details would be hidden initially, and upon clicking the next button, the next set of details would be displayed fo ...

Troubleshooting problems with navbar list alignment using Bootstrap

<div class="container"> <!--main div--> <div> <nav class="navbar navbar-light bg-light"> <a href="https://wwww.kidsedge.in" class="navbar-brand&qu ...

Enhancing a CSS-styled element using HTML

I created a style for an element using CSS: #box { background-color: white; } Then I placed the element within a div and it took on a different color. How can I change the color of the #box within the div? ...

The <p> element nested inside a <div> element with font-weight styling

I'm struggling to make a large font size and weight fit into a div tag while aligning it vertically at the bottom. Can anyone help me with this issue? div { border:1px solid black; height:100px; } table { border:1px sol ...

Adjust the visual design and style sheet of the website according to individual user

I am currently in the process of developing a product that we intend to white-label in the future. My main focus right now is finding the most efficient way to programmatically allow users to update basic design elements, such as header color, through thei ...

What is the best way to align elements on the left side in the center of my page when they are not adjacent in the DOM structure?

Let's consider a scenario where my website is structured with a header, footer, and main column. The main column holds the article and its table of contents side by side, with the center alignment. The width of the main column isn't fixed due to ...

The jQuery fadeToggle function toggles the visibility of an element starting from hidden instead

I'm having an issue where text in my div only appears on the second click, instead of the first. What could be causing this problem? $('#fPaperCirclePic').on('click', function () { $('#fPaperCircleText, #isargebla, #moq10 ...

Automatically resizing an image in CSS according to its dimensions and ensuring a similar div fills any remaining space

Seeking guidance on CSS and HTML, specifically relating to an article template I'm developing. The challenge lies in incorporating a picture on one side and a text box of equal height on the opposite side, both enclosed within div tags as shown below. ...

Troubleshooting the Bootstrap 4 Grid System

I am encountering some difficulties with the grid system in Bootstrap 4. I have a main content section with col-sm-9 and a right sidebar with col-sm-3 float-right. However, the sidebar does not align properly starting from the top, instead it appears just ...

Is it achievable to dynamically modify the style URL in an Angular component based on certain conditions?

element: I am working with two different CSS files, one for Arabic layout and one for English layout. I am wondering if it is possible to conditionally change the style URL in the component. Is this feasible? ...

Two keyframes are unable to function simultaneously

I am facing an issue with transitioning two divs, "hat" and "sock". The "hat" transition works as intended, but for some reason, the "sock" transition is not working. I have checked the properties and made sure they are set up in a similar way to "hat", ...

What are some creative ways to design nested flexboxes?

I'm currently working on creating a navigation bar using two nested flex boxes within one parent container. However, I'm facing difficulty in styling the inner flexbox without impacting the main container items. Here is how my layout is supposed ...

When using Semantic UI, displaying a list item with an image causes the text to be

I recently came across an interesting example on the Semantic UI website showcasing lists with items containing images positioned to the left. To view the example, visit: Everything seemed to work fine until I noticed that when using a long block of text ...

Seeking Answers About jQuery UI Themeroller

After designing a unique theme using http://jqueryui.com/themeroller/ and saving it, I have the theme downloaded. What is the next step to begin implementing the CSS for the theme? ...

What causes images to shift when resizing in Chrome, but not in Firefox or Safari?

My layout includes images - one on the left and two on the right. As I resize the browser window, the images scale accordingly. The issue arises when viewing my layout in Chrome: the image positions shift as I resize the browser, unlike Safari and Firefox ...

Animate input group width with Bootstrap 4

Currently, I am struggling to animate the width of an input element within a Bootstrap 4 navigation bar. The input is nested within an input-group along with a button on the right-hand side. My goal is to have the input initially hidden and expand when the ...

The hover effect is not functioning properly after loading jQuery with load();

When loading elements into a div using the load() function, I noticed that the :hover effect in CSS stops working for those elements. It's a dynamic menu setup, as shown below: <div id='main-menu'> <ul> <li class='click ...

Transforming item design in Flexbox when it wraps

Can styles be applied once an item wraps around? I have a two-column flexbox layout where the first item is fixed to the left and the second item should be centered in the remaining space. The solution mentioned here involves adding margin: auto to the se ...