Is it possible to change the order of elements in the navbar using HTML/Bootstrap depending on the state of the responsive menu toggle?

I am attempting to implement a responsive Bootstrap 4 navbar within Angular 8.

When the menu is closed, the element order is correct: COMPANY, BROWSE, LOGIN

The issue arises when I open the menu and the #menu receives the navbar-collapse flex attributes:

.navbar-collapse {
    flex-basis: 100%;
    flex-grow: 1;
    align-items: center;
}

However, this causes #company to shift right due to flex-basis: 100%, pushing #login below the entire menu.

<nav class="navbar navbar-expand-sm navbar-light bg-light">
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#menu">
        <span class="navbar-toggler-icon"></span>
    </button>
    <a class="navbar-brand" href="#" id="company">COMPANY</a>
    <div class="collapse navbar-collapse" id="menu">
        <div class="navbar-nav">
            <a class="nav-item nav-link" href="#">BROWSE</a>
        </div>
    </div>
    <div class="navbar-nav" id="login">
        <a class="nav-item nav-link" href="#">LOGIN</a>
    </div>
</nav>

I am facing challenges in ensuring that #menu does not impact #company and #login. My only solution was adjusting the elements' order using Bootstrap's order-* class, but this requires knowledge of the #menu toggle state.

How can I dynamically set the order based on the #menu toggle state? Alternatively, how can I prevent the elements from shifting?

Answer №1

in my specific situation

<nav class="navbar navbar-expand-lg">
        <a class="navbar-brand" href="about-us.html">
            <img class="img-responsive" src="../img/logo.png" alt=""/>
        </a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#menu" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"><i class="la la-bars"></i></span>
        </button>
        <div class="navbar-collapse collapse" id="menu">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item">
                    <a class="nav-item nav-link" href="#">BROWSE</a>
                </li>
            </ul>
        </div>
        <a class="nav-item nav-link" href="#">LOGIN</a>
    </nav>

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

Clickable link that directs to a particular tab on a webpage (cbpFWTabs)

I have been utilizing tabs from the codrops Tab Styles Inspiration and I am looking for a way to open specific tabs using URLs. For instance, if I wanted to open tab3, I could link it as www.google.com/index#tab3. Below is the code I am currently using: ...

Refreshing Django HTML table dynamically upon database updates

Currently, I have an HTML table set up using a Django template to showcase data from my database. I am looking to ensure that this table remains updated in real-time whenever the database undergoes changes. Despite my research efforts, there is limited inf ...

Include a new module in the declarations NgModule utilizing ts-morph

Currently, I am utilizing the ts-morph library and my objective is to add a new component to the declarations: This is my initial setup: @NgModule({ declarations: [], imports: [], providers: [], }) Here is what I am aiming for: @NgModule({ declarations: [ ...

Tips for implementing absolute import paths in a library project

In my workspace, I have a library with two projects: one for the library itself and another for a test application. ├── projects    ├── midi-app    └── midi-lib Within the workspace's tsconfig.json file, I set up paths for @a ...

Received an error stating, "0 arguments were provided when expecting 1-3" while attempting to run the ng build --prod command

I'm currently developing a navigation panel that displays hierarchy and child items when parent items are clicked: <div *ngFor="let t of temp(math.ceil(rr2.children.length/3)).fill(); let ei = index"> <!-- <div *ng ...

Incorporating HTTP headers into Angular 6

Could someone confirm if this method is correct for adding headers to http requests in Angular 6? Upon inspecting the call through SwaggerUI, it appears that the required headers are: url -X GET --header 'Accept: application/json' --header &apo ...

Is there a way to select multiple items using the same xpath in Python Selenium by clicking on them?

I am facing a challenge with my webpage code. The code snippet below presents a radio button setup: <label data-correct="false"> <input type="radio" ng-model="quizCtrl.state.selectedOptionForCurrentQuestion&quo ...

`place the table inside a hidden div`

I am trying to create a non-editable table that can be overlayed with a div under specific conditions. However, it seems like my current implementation is not working as expected. What could be causing this issue? CSS <style type="text/css"> # ...

The lightbox is triggered by clicking on a different div to display its content

Great news - my lightbox is up and running! Each image on my website corresponds to a different organization, and clicking on the image opens a specific lightbox. My question is: how can I have a lightbox configured so that only the trigger image is displ ...

Stretchable navigation cell

I am working on a navigation bar called "nav" that consists of a "ul" and "li". I have specified the display property for the "ul" as table and for the "li" as table-cell. Setting the "ul" to take up the full width of the wrapper ensures proper alignment. ...

Delete any content that is not enclosed in tags

I am struggling with manually rendering Django forms and it's producing the following code. Is there a way to remove text without HTML tags, such as "Currently:" and "Change:", which are difficult to style with CSS? <div class="row align-cente ...

The label overlay for MatInput remains fixed within the input box in an Angular form

I've encountered an issue with some of my form fields where the field label doesn't move up to the top border of the field when you start typing in the input box. Instead, it remains in the middle of the box, causing the characters you type to ov ...

Despite implementing it correctly, the redirect to a protected route after a user logs in is not functioning as

I've been working on an Angular tutorial and have managed to get it up and running. However, I'm facing an issue where my app does not redirect the user to any pages with the "canActivate [AuthGuard]" option enabled after login. Even when trying ...

Adding a text field on top of a div based on the dropdown value selection

I am working with a dropdown option inside a div. I want to make it so that when the last option is selected, a text box will appear on top of the dropdown. And when a different option is selected, the text box should be disabled. How can I achieve this? ...

What could be causing the Angular input [value] to execute the function() repeatedly?

While working on a simple code snippet to display input values from an array in a Typescript HTML template, I encountered an issue where the data wasn't loading quickly enough, resulting in errors until it was fully loaded. To solve this problem, I ad ...

Differentiating Between Observables and Callbacks

Although I have experience in Javascript, my knowledge of Angular 2 and Observables is limited. While researching Observables, I noticed similarities to callbacks but couldn't find any direct comparisons between the two. Google provided insights into ...

Tips on eliminating certain text from a hyperlink

I need assistance with removing the text  Title from my link while preserving the image. <tr id="group0"> <td colspan="100" nowrap="" class="ms-gb"> <a href="javascript:" onclick="javascript:ExpCollGroup('28-1_', ...

Is there a way for me to implement my custom CSS design within the Material UI Textfield component?

I have a project in Next.js where I need to create a registration form with custom styles. The issue I'm facing is that I'm struggling to customize a textField using my own CSS. I attempted to use the makeStyles function, but encountered a proble ...

Arranging two DIVs side by side

I am struggling with positioning a promo image next to a dropdown menu, which consists of several DIVs. Currently, the image is displaying below the menu due to using inline-block and block properties in the CSS styles. .menu{ background-color: whi ...

The problem with "em" in CSS: preventing it from scaling based on the font-size of a particular element

My website predominantly utilizes "em" for design over "px," which is meant to be more compatible with modern browsers. Most of the text is set at font-size:1em, where 1em equals 16px as a default without specific specification. However, there are sectio ...