Issue with responsiveness in Bootstrap's Navbar

I stumbled upon a code snippet online for creating a navbar using Bootstrap, and I must say, I love the design. However, when I try to resize my screen, it seems that the navbar is not responsive as expected. The links start disappearing and some weird things happen.

Below is the code for the navbar:

.navbar-new-top{
    background: #fff;
}
.navbar-brand{
    font-weight: 600;
}
.navbar-brand img{
    width: 20%;
}
.navbar-new-top ul{
    margin-right: 9%;
}
.navbar-new-top ul li{
    margin-right: 8%;
}
.navbar-new-bottom{
    background-color: #f7f7f7;
    box-shadow: 0 5px 6px -2px rgba(0,0,0,.3);
    border-top: 1px solid #e0e0e0;
    margin-top: 4%;
    height: 40px;
}
.navbar-new-bottom ul li{
    margin-left: 2%;
    margin-right: 2%;
}
.navbar-nav .nav-item a {
    color: #333;
    font-size: 14px;
    font-weight: 600;
    transition: 1s ease;
}
.navbar-nav .nav-item a:hover{
    color: #0062cc;
}
.dropdown-menu.show{
    background: #f8f9fa;
    border-radius: 0;
}
.header-btn{
    width: 161%;
    border: none;
    border-radius: 1rem;
    padding: 8%;
    background: #0062cc;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}
<nav class="navbar fixed-top navbar-expand-md flex-nowrap navbar-new-top">
            <a href="https://www.adopteunvpn.com/" class="navbar-brand"><img src="#" alt=""/>adopteunvpn.com</a>
            <ul class="nav navbar-nav mr-auto"></ul>
<?php echo 'Your IP address : &#x274C; ' . getIp(); ?>
                           <ul class="navbar-nav flex-row">

                <li class="nav-item">
                    <button type="button"  class="header-btn">Button</button>
                </li>
            </ul>
            <button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbar2">
                <span class="navbar-toggler-icon"></span>
            </button>
        </nav>
        <nav class="navbar fixed-top navbar-expand-md navbar-new-bottom">
            <div class="navbar-collapse collapse pt-2 pt-md-0" id="navbar2">

                <ul class="navbar-nav w-100 justify-content-center px-3">
                    <li class="nav-item active">
                        <a class="nav-link" href="#">Link</a>
                    </li>
                    <li class="nav-item">
                        <a  href="#" class="nav-link">Link</a></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link">Link</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link">Link</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link">Link</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link">Link</a>
                    </li>
                </ul>
            </div>
        </nav>

I have already included Bootstrap 4 in the header of my website.

Can someone please guide me on what might be going wrong here? As a beginner in CSS, I would really appreciate your help.

Thank you in advance!

Answer №1

To ensure the Li tag is displayed inline, you can apply the following CSS:

.nav_display{

    display: inline;
}

Don't forget to add the nav_display class to the Li tags in your navigation bar:

<ul class="navbar-nav w-100 justify-content-center px-3" style=" list-style-type: none;">
                    <li class="nav-item nav_display active">
                        <a class="nav-link" href="#">Link</a>
                    </li>
                    <li class="nav-item nav_display">
                        <a href="#" class="nav-link">Link</a>
                    </li>
                    <li class="nav-item nav_display">
                        <a class="nav-link">Link</a>
                    </li>
                    <li class="nav-item nav_display">
                        <a class="nav-link">Link</a>
                    </li>
                    <li class="nav-item nav_display">
                        <a class="nav-link">Link</a>
                    </li>
                    <li class="nav-item nav_display">
                        <a class="nav-link">Link</a>
                    </li>
                </ul>

In order to make the design responsive, make sure to remove the width: 161%; property from the .header-btn class. Additionally, eliminate the class

<div class="navbar-collapse collapse pt-2 pt-md-0" id="navbar2">
and keep only the id.

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

``There seems to be an issue with setting the input value attribute using jQuery's .html

I've been trying to update the value attribute in the input element within my HTML code, but so far, I haven't had any luck with it. HTML: <div class='photo-info'> Photo Name : <span class='photo-name'><?p ...

The proximity between two columns of HTML elements is not closely aligned

Currently, my web app has two columns when the screen size is big enough. https://i.sstatic.net/aQPlF.png The spacing between the elements in the left column and the one below it is causing an issue that I want to address. .thumnnail { display: inl ...

Achieving compatibility between angular-bootstrap modal and angular-1.3

Wondering if anyone has managed to successfully use angular-bootstrap modals with angular-1.3.x? I've had no issues with my modals on angular-1.2.x, but as soon as I upgraded to angular-1.3.11, the modals stopped showing up. When I click the button ...

To determine the class of an element and reveal its parent if the class is present

Typically, the parent element remains hidden by default. However, upon clicking a specific element, its child might gain a class called "selected". How can I check for this class and then display the entire list if it is present? <ul style="display: ...

Update the available choices in one select field based on the choice made in another

I am working on a feature where users can select their country, either USA or Canada. Currently, I have all the American states listed in one dropdown menu. However, I want this dropdown to change to display Canadian provinces when users select Canada. Bel ...

Converting table data to JSON using JavaScript, including rows for "parent" and "children."

To create a JSON object by selecting values from multiple rows of a table using checkboxes, follow the structure below. The parent row, identified by the class 'primary color,' will be included in the JSON, along with the selected child rows. The ...

Invoking a controller method with a boolean return type directly from the _layout page

Is it possible to utilize the boolean value returned by a method in a controller within _Layout.cshtml? I want to evaluate this value and then direct to a different action based on the result. [HttpGet] public bool CheckPagePermission(Page ...

What could be causing my navigation bar to not fully extend across the width of the browser with the codes I am currently using

After implementing the CSS code provided below, my goal was to create a navigation bar that spans the entire width of the browser and features a striking red background. Additionally, I intended to position the logo on the furthest left side with text dire ...

Can jqplot be used to create this particular graph?

Can the graph be created using jqplot as shown below? The closest graph type is stacked, but there are issues with coloring and point labels. This jsfiddle showcases my attempt to create a bar chart with its legend and point labels. Is it possible to achi ...

Executing a function in JQuery

Hello everyone, I am looking to execute this script: <script type="text/javascript"> /* var bcf_settings = { buttonText:'Contact Us', buttonTop:'30%', language:'en_US' }; // Better Contact Form Settings */ (func ...

Using jQuery to enhance your input labels

<div id="one"> <label for="number">Number</label> <div id="two"> <input id="number" type="text" name="number"> </div> </div> This displays the following: Number [input] Is there a way to ...

Anchor tags created using JQuery will remain on the same page without redirecting

Presented below is the code I have utilized to construct the anchor tag along with its content. $('div#right-slide').html("<a href=\"http://www.XXXXXXXXXXXX.info/limited-specials/\" ><h1 id=\"specials\">Click Here ...

Looking to implement URL navigation based on a selected value from a dropdown menu when the onClick button is pressed

I am struggling with getting the Go Button to navigate to a specific URL like "&age=10" without selecting it. I require assistance with creating code that will allow me to redirect to the URL with post URL variables for my WordPress site. ...

How can I fix the "element is not defined" error in JavaScript when using Get

Having some issues displaying the #coupon using JavaScript, as I am encountering an error message stating that getElementById is undefined. Code Snippet (HTML) <html> <head> <title>Exercise</title> <link rel="styles ...

Finding content in HTML tables using JavaScript and jQuery

I recently created a table and wanted to add a search functionality to it. I searched online, including on various forums like StackOverflow, but unfortunately, the solutions I found did not seem to work for me. Below is the code that contains both the HT ...

Minimizing the frequency of getElementById calls for the same HTML element

When dealing with repetitive function calls using the same element as a parameter, is it more effective to store the element as a global variable? For instance, imagine a function that is triggered on every key press and takes an element as an argument. ...

Maintaining uniformity in Python by assigning and populating empty values for any missing HTML tags to ensure consistency across structures

Here are the HTML lines I currently have: <nonDerivativeTable> <nonDerivativeHolding> # First Holding <securityTitle> <value>Common Stock</value> </securityTitle> <ownershipNat ...

Troubleshooting: Issues with HTML page not loading while running a JavaScript server

Currently, I am in the process of developing a game using a combination of HTML, CSS, and JavaScript. I'm exploring the integration of template engines and AJAX into the project. In order to achieve this, I have set up a server that, when executed in ...

What is the best way to overlay text onto a background image using Material UI's Card and CardMedia components?

Using the card component, I have successfully added a background image. However, I am facing difficulty in figuring out how to overlay text on top of this image. If anyone has suggestions or alternative methods, please feel free to share! <Card> ...

Ajax is updating the information stored in the Data variable

Recently, I reached out to tech support for help with an issue related to Ajax not executing properly due to Access-Control-Allow-Origin problems. Fortunately, the technician was able to resolve the issue by adding a file named .htaccess with the code Head ...