Issue with Bootstrap navbar not collapsing to pills at the appropriate moment

Currently, my navbar contains links on the left side and social media buttons on the right. The issue arises when I resize the window - instead of collapsing into pills as desired, the social media buttons move under the links, creating a messy layout. Eventually, the links collapse into pills only when the window is too narrow.

How can I adjust the code so that the navbar collapses at the appropriate position? Any assistance would be greatly appreciated :)

Below is the current code:

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">WebsiteName</a>
        </div>
        <div class="collapse navbar-collapse" id="myNavbar">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">Link1</a></li>
                <li><a href="#">Link2</a></li>
                <li><a href="#">Link3</a></li>
                <li><a href="#">Link4</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right nav-pills social-icons icon-circle icon-rotate">
                <li><a href="#"><i class="fa fa-facebook"></i></a></li>
                <li><a href="#"><i class="fa fa-instagram"></i></a></li>
                <li><a href="#"><i class="fa fa-twitter"></i></a></li>
            </ul>
        </div>
    </div>
</nav>

Answer №1

Adjust the width to your preference instead of 1000px.

@media (max-width: 1000px) {
      .navbar-header {
          float: none;
      }
      .navbar-left,.navbar-right {
          float: none !important;
      }
      .navbar-toggle {
          display: block;
      }
      .navbar-collapse {
          border-top: 1px solid transparent;
          box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
      }
      .navbar-fixed-top {
          top: 0;
          border-width: 0 0 1px;
      }
      .navbar-collapse.collapse {
          display: none!important;
      }
      .navbar-nav {
          float: none!important;
          margin-top: 7.5px;
      }
      .navbar-nav>li {
          float: none;
      }
      .navbar-nav>li>a {
          padding-top: 10px;
          padding-bottom: 10px;
      }
      .collapse.in{
          display:block !important;
      }
    }

Answer №2

Utilize a class that dynamically sets the width of the navbar based on screen size.

@media ( max-width : 767px ) {
  .widthNavbar {
    width : 700px;
  }
}

Alternatively, activate the class between two specific values:

 @media ( min-width : 768px ) and ( max-width : 979px ) {
   .widthNavbar {
     width : 700px;
   }
 }

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

How can I overlay a background image on top of another div?

This inquiry might not be the most trendy, but I am seeking guidance on the best approach to tackle this task, utilizing HTML, CSS, and Bootstrap. For reference, something similar to the image at this link. ...

Unable to load the header file as required

As I work on developing my website, I have implemented PHP to include a standard header page across all subsequent pages. The header is basic, containing the navigation bar, logo, and other elements. While the require("header.php") function works for most ...

Implementing Bootstrap 5 JS within an Angular 11 component TypeScript

I am currently working on a project that utilizes Angular 11 and we are aiming to integrate Bootstrap 5 native JS without relying on third-party libraries like ng-bootstrap, MDB, or ngx-bootstrap (jQuery is not being used as well). I understand that using ...

Several validation checks - logic malfunction

I have implemented a validation feature for passwords on a form, but I suspect there may be a logic error in my code that I haven't caught yet (blame it on the coffee machine!). Take a look at the JavaScript below: <script type="text/javascript"& ...

Is there a way to remove the unwanted code ​ from the client side of my website?

Upon inspecting the source code of a webpage, I noticed an odd character ​ appearing before the <script> tag on the client side. Strangely, this mysterious character is not present anywhere in the server-side PHP file. I attempted removing a ...

What is the most efficient method for incorporating fonts.googleapis.com into CSS files for use on both HTTP and HTTPS pages?

My website functions correctly when accessed through URLs that start with either http:// or default to the http protocol if not specified. However, an error occurs stating that the main.css file cannot be found when the URL begins with https://. The lates ...

Is it possible to incorporate personalized JavaScript alongside bootstrap?

Just recently started using bootstrap and was curious about something. Can custom JavaScript be integrated with bootstrap buttons without any additional adjustments? ...

Is there a way to achieve the desired outcome without relying on Bootstrap?

I stumbled upon a code snippet in an online article which showcased a live demo accessible through this link Upon further investigation, I managed to craft a simple modal using just a few lines of jquery and CSS without relying on bootstrap. For instance ...

Having trouble retrieving the contents of a <div> tag within a JavaScript function

Javascript Code In First ContentPlaceHolder :- <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <script type="text/javascript" > function PrintElem(elem) { alert(elem); Popup($(elem).html()); } ...

On the upper right corner, you'll find a dropdown feature that, when clicked, displays a list of items on

Problem Description The dropdown menu appears on the top right side and displays items on the top left side when clicked. How to reproduce? To replicate the issue, please ensure that the window is maximized. Steps Taken So Far: Link to JS Fiddle Code ...

What is the best way to transform XML into a two-dimensional array using JavaScript?

I really need to store the array in a variable. Currently, I am utilizing .DataTable for pagination. However, it doesn't support tables generated from XML using JavaScript. Based on this source, I have to convert my XML into a 2D array. Below is the ...

Is it possible to remove the color change from the Angular Material Pagination select?

While using md-table-pagination in Angular Material, I am facing an issue where the color of the selected page changes from white to black every time I click on a desired row per page. Is there a way to make sure that the label stays white even after click ...

Guide on creating a donut visualization with canvas?

I am in need of assistance, as I am trying to create a donut chart using canvas and JavaScript. Here is the code I have so far, but I am unsure how to complete it: <body> <canvas id="chart" width="500" height="500" style="background-color:bl ...

Is there a way to dynamically change select2 styling using code when a form is submitted?

Having trouble highlighting empty select2 selects when a form is submitted? I'm struggling to override my existing CSS styling upon document load. Check out my jQuery attempt: var $requiredUnfilledItems = $(".required:not(.filled)"); if ($requiredUn ...

How to position an absolute element beneath a fixed element

My website is experiencing a problem where the fixed header is overlapping an absolute paragraph on this page. Does anyone know how to resolve this issue? ...

Creating a line using CSS to connect two elements

I've been attempting to divide a series of circles with a line down the center. However, when I position a line (.Line1) to run between the first and last circle, it appears centered at the top left of the first circle instead of being truly centraliz ...

Only referring to a CSS class within a particular element

I have defined the following CSS: .grade a{ color: white; } It is working, but maybe too well... Now, I have an HTML structure like this: <li class="grade"> <a><i class="fa fa-star fa-fw"></i></a> My Text < ...

How can a div's height be adjusted based on the content of one sub div but not the other?

If I have a parent div with two child divs inside it, is it possible to set the parent div's height to auto, but only apply it to one of the child divs, while having the other child set to scroll for overflow-y? For example, you can see the issue her ...

Sort div elements based on checkbox filters

I have a set of checkboxes that I want to use for filtering purposes. <div class="filter"> <div class="checkbox"> <label><input type="checkbox" rel="canada"/>Canada</label> </div> <div class="chec ...

Hide the first dot indicator on the carousel when it is clicked

I've been experiencing a strange issue with my carousel - whenever I click on any of the dots, dot1 disappears. Upon inspecting the CSS, I found out that when clicking on a dot, it receives a display:none property from somewhere. Here is the code for ...