How to Customize the Navbar Position in Bootstrap 3 when the Brand/Logo is Collapsed

I am currently in the process of creating my first website and experimenting with the Bootstrap 3 framework.

The navbar I have selected is designed to adjust based on screen size, collapsing into a small button for use on tablets and mobile devices.

However, I am not completely satisfied with the default position of the collapsed navbar items. I would prefer them to appear below the logo rather than right next to it as shown in this screenshot:

As the screen width decreases, the issue becomes more pronounced:

The navbar collapses when the width reaches 767px. While exploring the Bootstrap CSS files, I noticed several @media queries but I am unsure which one will help me achieve the desired layout where the navbar items drop below the logo when collapsed.

Below is the navigation section of my HTML code (CSS and JS are linked from the Bootstrap files).

<header>

    <!-- navigation -->
    <div class="navbar navbar-default navbar-static-top">
        <div class="container">

            <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

            <a class="navbar-brand" href="#" id="MyLogo">LOGO HERE</a>

            <div class="collapse navbar-collapse navbar-responsive-collapse">

                <ul class="nav navbar-nav navbar-right">
                    <li class="active"><a href="#">HOME</a></li>
                    <li><a href="#">PAGE 1</a></li>
                    <li><a href="#">PAGE 2</a></li>
                    <li><a href="#">PAGE 3</a></li>
                    <li><a href="#">PAGE 4</a></li>
                    <li><a href="#">PAGE 5</a></li>
                </ul>

            </div>
        </div>
    </div>

</header>

Answer №1

When I tested your code on Jfiddle, I encountered the same issue as you did. It seems that some parts of your code are incorrect. Bootstrap should ideally function in a way that automatically collapses the navigation below the logo.

You missed enclosing the buttons and brand inside the navbar-header div. Here is the corrected version:

<header>

<!-- navigation -->
<div class="navbar navbar-default navbar-static-top">
    <div class="container">

     <div class="navbar-header"><!-- Place navbar-header here -->

        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-responsive-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#" id="MyLogo">LOGO HERE</a>

        </div><!-- End header section here -->

       <div class="collapse navbar-collapse navbar-responsive-collapse">

            <ul class="nav navbar-nav navbar-right">
                <li class="active"><a href="#">HOME</a></li>
                <li><a href="#">PAGE 1</a></li>
                <li><a href="#">PAGE 2</a></li>
                <li><a href="#">PAGE 3</a></li>
                <li><a href="#">PAGE 4</a></li>
                <li><a href="#">PAGE 5</a></li>
            </ul>

        </div>
    </div>
</div>

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

jQuery Mobile and Phonegap: Content Disappears from Page Header After Transition Finish

My phonegap (2.2.0) + jquery mobile (1.2.0) app is experiencing a peculiar problem. There is a page in my app with a link that loads another page. On the loaded page, there is a back button that takes the user back to the previous page when clicked. This ...

Template for Joomla with a white stripe running along the right side

When I resize my browser to be half the width of my screen at www.thames.ikas.sk, a white stripe appears on the right side. Why is this happening? Why aren't my html and body elements taking up the full width of the browser? This issue doesn't oc ...

Strategies to verify if two objects of the same class possess the same attribute

I have multiple elements with the same class and unique attribute values, such as: <div class="myclass" data-attr="1"></div> <div class="myclass" data-attr="2"></div> <div class="myclass" data-attr="3"></div> <div cl ...

jQuery ajaxSetup: handling error retries for ajax calls is not possible

When using $.ajaxSetup(), I am faced with the challenge of making an AJAX request after refreshing a valid token in case the previous token has expired. The issue arises when attempting to execute $.ajax(this) within the error callback. $.ajax({ url: ...

Modify the innerHTML to adjust font size when a button is clicked in Ionic 5, or eliminate any unnecessary spaces

I have been experimenting with changing the font size of a variable in .html when the variable contains whitespace. In my .ts page, I use the following code to remove the whitespace: this.contents = this.sanitizer.bypassSecurityTrustHtml(this.product[&apos ...

What is preventing me from executing node.js and socket.io within a screen or utilizing Forever?

I'm encountering an issue with running nodejs in a screen. The problem arises when I leave the screen and no sockets are connected. The next person trying to connect will face an error message until the screen is reopened using screen -R node. Once th ...

wrap <td> data in a link with vue depending on certain conditions

I'm trying to customize the display of a particular table cell td. I want to show the data in a link if a certain condition is met, and if not, just show the data as text. However, I'm encountering some difficulties in implementing this. I have ...

Having trouble adding items to an array within a Javascript promise

I am facing an issue with the exported function in a Nextjs app, which acts as an API page. The problem arises when the 'domainnames' array returns nothing in the 200 response. Interestingly, if I exclude the 'GetDomainStatus()' funct ...

The success function in $.ajax not being triggered

In the .js file, there is a function that invokes a webservice method named getStudents: [WebMethod(Description = "white student list")] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<Job> getStudents(long classId) ...

Splitting the page in half

Is there a way to ensure that the LeftArea and wuiMainPageNav sections stay side by side regardless of the browser window size? When I resize the window, the layout gets messed up with wuiMainPageNav moving down. Any suggestions on how to address this issu ...

Grasping the idea of elevating state in React

I can't figure out why the setPostList([...postList, post]) is not working as expected in my code. My attempts to lift the state up have failed. What could be causing this issue? The postList array doesn't seem to be updating properly. I'v ...

Using a forward slash in the path for the href attribute in a CSS link within an ejs file

Image 1: Configuring express.static for the public folder Image 2: Adding href="/app.css" in post.ejs file Image 3: Final result While experimenting with using /app.css and app.css in the post.ejs file, I noticed that the outcome was consistent with th ...

Ways to create a group label to modify various textboxes when a click event occurs

Is it possible to change multiple textboxes with corresponding labels after a click event? Issue: The current output only displays the value of the last textbox. $(function () { $('a.edit').on('click', function (e) { e.pre ...

Converting information from a model into individual variables

I'm a newcomer to typescript and angular, and I've been attempting to retrieve data from firebase using angularfire2. I want to assign this data to variables for use in other functions later on. I am accustomed to accessing object members using d ...

Using a Javascript method to access a sibling property within an object

Is there a way to access a sibling property from a method in JavaScript? This seemingly simple task has proven challenging for me. Take a look at the sample code below. let f = { a: 3, printMyBrother() { console.log(X) } }.printMyBrother f() ...

Guide to assigning a value to a model in AngularJS by utilizing a select input with an array of objects

I'm new to AngularJS and I've encountered a challenge that requires an elegant solution. My application receives a list from the server, which is used as the data source for the select tag's options. Let's assume this list represents a ...

Combining two arrays by finding common elements

Currently, I am working on a project where I retrieve data from the server, and each piece of data has to adhere to a specific format: const DATA = [ { title: {title: 'Main dishes'}, data: [ {_id: 1, type: 'Pizza'}, ...

Issue with jQuery: Android browser receiving XML instead of JSON from HTTP POST request

When attempting to make an HTTP POST request using jQuery in older Android browsers, I encounter a specific issue. The response received is: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <application xmlns="http://wadl.dev.java.net/20 ...

the bootstrap data-target attribute is malfunctioning

I've been working on a website design with bootstrap, but for some reason, the data-target attribute isn't functioning as expected. Below is a snippet of my code: <button class="navbar-toggle" data-toggle="collapse" data-target=".navHea ...

generate a JSON cookie using express

Having trouble creating a cookie in express 3.x. I'm attempting to set the cookie using the following JSON: res.cookie('cart', { styles: styles[product], count: 0, total: 0 }) The ...