Guide to aligning two navbar-collapse contents in a single line

I need to collapse the navigation bar content. I would like to have these contents displayed in the same line (inline).

<header class="navbar navbar-fixed-top" role="navigation">
<div class="navbar-inner">
    <div class="container">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-rt-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-mid-collapse">
            <span class="glyphicon glyphicon-search"></span>
        </button>
        <a class="navbar-brand" rel="home" href="">My Project</a>
        <div class="collapse navbar-collapse" id="navbar-mid-collapse">
                <form class="navbar-form form-inline" role="search" method="get" id="search-form" name="search-form">
                    <div class="input-group">
                        <input type="text" class="form-control">

                        <div class="input-group-btn">
                            <button type="submit" class="btn btn-success"><span
                                    class="glyphicon glyphicon-search"></span></button>
                        </div>
                    </div>
                </form>
        </div>
        <div class="collapse navbar-collapse" id="navbar-rt-collapse">
            <ul class="nav navbar-nav">
                <li><a data-toggle="modal" href="#" data-target="#">Login</a></li>
                <li><a data-toggle="modal" href="#" data-target="#">Register</a></li>
            </ul>
        </div>
    </div>
</div>

How can I display #nabar-mid-collapse and #navbar-rt-collapse in the same line? Thank you!

Answer №1

To achieve your desired outcome, you'll need to make some adjustments to your CSS and HTML code:

CSS Changes:

body {
    padding-top: 50px;
}
.navbar-inverse .navbar-toggle {
    color: #fff;
    width: 44px;
    height: 36px;
}
@media (max-width: 767px) {
    .navbar-inverse .navbar-collapse .navbar-form{
        margin: 0;
        border: 0 none;
    }
    .navbar-form .form-group {
        float: left;
        min-width: 80%;
        margin-right: 10px;
    }
}
@media (min-width: 768px) {
    .navbar-collapse.collapse {
        display: inline-block!important;
        float: left;
    }
}

HTML Modifications:

<header class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target="#navbar-rt-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <button type="button" class="navbar-toggle pull-right" data-toggle="collapse" data-target="#navbar-mid-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="glyphicon glyphicon-search"></span>
            </button>
        <a class="navbar-brand" rel="home" href="">My Project</a>
        </div>
        <div class="navbar-collapse collapse" id="navbar-mid-collapse">
          <form class="navbar-form" role="search">
            <div class="form-group">
              <input type="text" class="form-control" placeholder="Search">
            </div>
            <button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-search"></span></button>
          </form>
        </div>
        <div class="navbar-collapse collapse" id="navbar-rt-collapse">
          <ul class="nav navbar-nav">
                <li><a data-toggle="modal" href="#" data-target="#">Login</a></li>
                <li><a data-toggle="modal" href="#" data-target="#">Register</a></li>
          </ul>
        </div>
    </div>
</header>

Check out the Bootply Demo for reference.

Answer №2

To create a responsive layout, enclose #nabar-mid-collapse and #navbar-rt-collapse within a div with the class row-fluid.

Next, assign the class col-xs-4 (or any appropriate .col class based on your desired width) to both elements.

For more information on creating grids, refer to the grid system section in the Bootstrap CSS documentation.

Check out this demo for a visual example.

Answer №3

When faced with a problem, I found inspiration in @jme11's solution to tackle it this way:

// Utilizing multiple .navbar-collapse.collapse declarations
@media (max-width: 767px) {
    .navbar-collapse:after {
        clear:both;
    }
}
@media (min-width: 768px) {
    .navbar-collapse:after {
        clear:none;
    }
}

I hope this approach proves helpful to others encountering the same issue.

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

Implementing a PHP script to prompt the user to input two random integers and sum them up on a webpage through $_POST method

My current project involves creating an interactive adding game using PHP and HTML. In this game, the user is required to guess the correct sum of two randomly generated integers. However, I am encountering an issue where each time the user submits their a ...

Inspector, please demonstrate how to receive the most recent value from the 3-second update

On my index.php page, I have a JavaScript function that retrieves JSON data from data.php every 3 seconds. The data.php file ends with the following line: echo json_encode($row); When inspecting the index.php page, I see a few objects that are refreshe ...

Tips for retrieving the data attribute from a clicked a href tag using jQuery

I am facing an issue with passing the ID to the API URL in AJAX. When I click on the a href tag, the success function does not receive any response. First, I need to fetch all the albums, and that part has already been successfully completed. Here is the ...

Send information to PHP controller using DataTables Ajax functionality

Utilizing the DataTables library for Jquery, I am attempting to POST some basic data to a controller that contains a SQL query. The query will retrieve JSON data that I can manipulate as needed. When I use standard jQuery AJAX, everything functions proper ...

Having difficulty replicating the same effect across all five canvas elements

After following the code provided by j08691 here for canvas, everything worked flawlessly. However, I encountered an error in JavaScript when trying to implement it on multiple canvas elements. As a beginner in JavaScript, I would greatly appreciate any as ...

What is the technique for enabling a mouse click in the vicinity of an element?

During a presentation on React at a conference, I witnessed the speaker introduce a feature that allowed users to click and drag a divider on the screen by simply getting close to it instead of having to click directly on it. This concept adds to usabilit ...

Using HTML and Javascript to submit a form and display the results within a shadowbox

Hey there! I've got a form set up for users to input a search term. When the form is submitted, I'm looking to have the results from the "search.php" page appear in an iframe within a shadowbox (utilizing the shadowbox.js library). Unsure if this ...

Loading the static content page in Ionic can be slower the first time on a mobile device

My static page contains over 300 lines of text within the HTML file. <ion-content> <p text-warp> //my text with </p> </ion-content> When I view this page in my browser, it loads immediately. However, ...

Utilizing dual identifiers in a Jquery plugin

I am currently working with a jQuery plugin and I need to apply the same functionality to two different IDs. How can I achieve this? It involves a next and previous functionality where clicking on the next button automatically scrolls both divs. The issu ...

Uploading data through AJAX without saving it in the database

Can someone please assist me? I am encountering an issue where I am uploading multiple data using an AJAX request. The data appears to upload successfully as I receive a response of 200 OK, but for some reason, the data is not being stored in the database. ...

Use the angular cli to incorporate the CSS styles found in the node_modules directory

After successfully installing a new library with npm, I now face the challenge of importing the CSS into my project. It seems unwise to directly link to the node_modules folder. Can anyone suggest an easy way to import this CSS into my Angular CLI project? ...

There was a json parsing error that occurred due to an uncaught TypeError. The error message stated that the 'in' operator cannot be used to search for '1009'

I'm currently working on a project where my application makes an Ajax call to a PHP script that returns data encoded in json_encode. The PHP script is returning the data as expected. However, when attempting to parse it in jQuery, I encounter a conso ...

Select box in material design does not show an error when the value is empty

<md-input-container flex-gt-xs> <label translate>rule.type.title</label> <md-select name="type" ng-required="true" ng-model="vm.model.type" ng-change="vm.onRuleTypeChange(vm.model.type)"> <md-op ...

On paste events, CKEditor will strip away all HTML tags except for div and span elements

I am trying to implement a feature in CKeditor where all HTML tags are removed when a user pastes content using Ctrl+v. The code I have written so far does not seem to work as expected. <script type="text/javascript"> CKEDITOR.on('instanceR ...

Title of Json File and Invocation

Hey, I'm facing a simple issue with Angular and JSON. Basically, there are two JSON files that have the same "systemCode" in all objects: subCat.json and category.json Take a look at these lines: "systemCode": { "Key" : "1201", "open" : false }, ...

Trouble with flex wrap in my design template using Material UI

How can I create a responsive template using flexbox wrapping method? <Box sx={{ padding: 0, margin: 0, listStyle: "none", display: "flex", flexFlow: ...

What is the best way to send information from my HTML page to a listener?

I am in the process of designing a user interface for an Automated Parking System. In order to test if my page successfully sends out data from a form to a listener, I have written this code. However, I am facing some issues and would appreciate any assist ...

Unable to invoke Controller function using ajax request

I have come across a similar question that was addressed on this forum. Despite trying numerous solutions from stackoverflow, I have not been able to resolve the issue at hand. Therefore, I am seeking suggestions from your expertise. My challenge involves ...

Designing a Dynamic Floating Element that Shifts with Scroll Movement

Hey there everyone!, I am currently working on a project in Wordpress and I was wondering if anyone has experience creating a floating widget that moves along with the page as you scroll. Any suggestions on how to achieve this? Would it involve using Javas ...

Utilize Xpath to transition between different html tags seamlessly

Here is the HTML snippet I am working with: <pre> <span class="cm-string">"userId"</span> ":" <span class="cm-string">"abc"</span> "," </pre> My goal is to extract the text "abc" from the "userId" tag, which changes fr ...