What is the best way to ensure the hamburger menu stays perfectly centered?

My menu is currently aligned to the right and scrolls with the user profile. I want the menu to always be centered and the profile to stay on the right side.

I am working with Angular 12 and Bootstrap 5 for this project.

Here is the code I have been using along with some images showcasing the desired layout:

Thank you!

Find the code at this StackBlitz link

https://i.sstatic.net/W8hI3.png

https://i.sstatic.net/cL3cg.jpg

<nav
  class="navbar navbar-expand-lg navbar-dark bg-primary"
>
  <div class="container-fluid">
    <a class="navbar-brand"
      ><img src="../../../assets/Targaryen.ico"
    /></a>

    <button
      class="navbar-toggler justify-content-center"
      type="button"
      data-bs-toggle="collapse"
      data-bs-target="#navbarTogglerbur"
      aria-controls="navbarTogglerbur"
      aria-expanded="false"
      aria-label="Toggle navigation"

    >
    <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse justify-content-center" id="navbarTogglerbur">
      <ul class="navbar-nav  justify-content-center mt-lg-0">
        <li class="nav-item">
        </li>
        <li class="nav-item">
        </li>
        <li class="nav-item">
        </li>
        <li class="nav-item">
        </li>
      </ul>
    </div>

    <div class="dropdown">
      <img
        src="{{ info.photoURL }}"
      />
      <ul
        class="dropdown-menu dropdown-menu-end dropdown-menu-dark"
        aria-labelledby="dropdownMenuButton1"
      >
        <li class="dropdown-item" >
        </li>
        <li class="dropdown-item" >
        </li>
      </ul>
    </div>
  </div>
</nav>

Answer №1

To maintain the layout of the website, you can rearrange the placement of the elements by swapping the navbar-nav and dropdown. Additionally, apply the order-lg-last class to the dropdown section in order to keep it positioned on the right side for lg screens...

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <div class="container-fluid">
        <a class="navbar-brand"><img src="//via.placeholder.com/30" /></a>
        <button class="navbar-toggler justify-content-center" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerbur" aria-controls="navbarTogglerbur" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="dropdown order-lg-last">
            <img src="//via.placeholder.com/30" />
            <ul class="dropdown-menu dropdown-menu-end dropdown-menu-dark" aria-labelledby="dropdownMenuButton1">
                <li class="dropdown-item">
                    <a href>Item</a>
                </li>
                <li class="dropdown-item">
                    <a href>Item</a>
                </li>
            </ul>
        </div>
        <div class="collapse navbar-collapse justify-content-center" id="navbarTogglerbur">
            <ul class="navbar-nav justify-content-center mt-lg-0">
                <li class="nav-item">
                    <a href class="nav-link">Item</a>
                </li>
                <li class="nav-item">
                    <a href class="nav-link">Item</a>
                </li>
                <li class="nav-item">
                    <a href class="nav-link">Item</a>
                </li>
                <li class="nav-item">
                    <a href class="nav-link">Item</a>
                </li>
            </ul>
        </div>
    </div>
</nav>

Codeply

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

Unique layout design that organizes calendar using nested divs with flexbox - no

I am having difficulties achieving the desired outcome with my calendar header layout implemented using flexbox for the years, months, and days. What could be the issue? Is it due to the structure of the HTML or is there something missing in the CSS? The ...

Attempting to extract data from an HTML table and store it in an array using JavaScript with the help of jQuery

Currently, I am faced with a challenge involving extracting values from an HTML table and storing them in a 2-dimensional array using JavaScript. jQuery seems like the ideal solution for this task. While I have managed to get the indices working properly, ...

Creating a dynamic dropdown menu triggered by a button click using Angular

I am a beginner in Angular (typescript) and I am facing some challenges in adding a new dropdown menu when a user clicks a button. My main struggle is creating additional attribute fields. I'm considering keeping track of the newly added dropdowns wit ...

jQuery: Revealing or concealing several divs upon selection alteration

When I populate a form, I want to display or hide multiple divs based on the OPTION selected in a DROPDOWN. Currently, my code works but the issue is that one div can be hidden or shown by multiple OPTIONS. As a result, these divs keep toggling between hi ...

Arrange data into columns on a website

In my project, I'm exploring the challenge of creating a square 2 x 2 grid alongside a rectangular column on the right-hand side. While attempting to implement a grid system for the 2 x 2 layout, I encountered issues with the alignment of the rectang ...

What is the best method to ensure that none of the select option values are left empty?

I have a total of 5 select option drop down menus currently, but this number may increase in the future depending on requirements. The issue I'm facing is that when I select the last element, it returns true even though the other elements are empty. I ...

Unlimited Lunch Options and Navigational Links

Looking for help with displaying the ul for MAINTENANCE and referencing specified classes from a CSS style sheet that are working elsewhere. However, the sub menu for MAINTENANCE is not showing up. Any suggestions? /* * Superfish v1.4.8 - jQuery menu w ...

Verifying that the class name prefix aligns with the folder name using Stylelint

Currently, I am utilizing the "selector-class-pattern" rule from stylelint. My chosen pattern enforces the ECSS naming convention. The specific rule configuration is outlined below: "selector-class-pattern": ["^[a-z]([a-z0-9]){1,3}-[A-Z][a-zA-Z0-9]+(_[A-Z ...

Embed a video clip into an HTML webpage

I attempted to embed a video using HTML. I followed the player script instructions and added the necessary paths and scripts, but unfortunately, the video is not visible on the webpage. Instead, when clicking on the area where the video should be, it opens ...

What process allows for this Twitter API response to be converted into HTML format automatically?

It is common knowledge that Twitter operates in an API-centric manner, meaning all Twitter apps retrieve their data through the API. Upon accessing (or .xml for those who prefer), a JSON formatted result with plaintext content and no additional formattin ...

Trouble adjusting opacity with CSS in @media queries for maximum width restrictions

When building a webpage with a collapsible header and a fading large logo that transitions to a smaller version in a different location upon scrolling down on the desktop view, there seems to be an issue. The smaller logo's opacity property does not r ...

"Get rid of the arrow in Bootstrap's dropdown menu

I'm currently using a bootstrap template that features an accordion menu. However, I have come across a scenario on one section of the page where I do not require the items to expand and show additional text, therefore, I would like to remove the arro ...

Uh-oh! A circular dependency has been detected in the Dependency Injection for UserService. Let's untangle this web and fix the issue!

Encountering the following error: "ERROR Error: Uncaught (in promise): Error: NG0200: Circular dependency in DI detected for UserService." The auth.component.ts utilizes the UserService and User classes, while the user.service.ts only uses the User class. ...

Warning displayed on form input still allows submission

How can I prevent users from inserting certain words in a form on my website? Even though my code detects these words and displays a popup message, the form still submits the data once the user acknowledges the message. The strange behavior has me puzzled. ...

Using Styled Components to achieve full width for input tag in relation to its parent

I am working with an input field that has a specific width set. My goal is to increase the width of this input field to 100% by selecting it from its parent component. Is there a way to achieve this without passing an explicit width prop in the styled c ...

What is the process of adding CSS effects to a button when a keypress activates it?

Do you have a CSS style that transforms the look of a button when clicked on-page? Want to extend this effect to when the button is activated via keyboard? (In essence, browsers allow activating a button by pressing Tab to give it focus and then hitting S ...

In AngularJS, how can you filter the ng-repeat value by clicking on a checkbox field?

Hey there, I'm looking to filter the ng-repeat value when a checkbox is clicked. Check out my Plunker here. By checking the checkbox labeled Role block, it should only show elements with roles value of "block". Similarly, by checking the checkbo ...

FirebaseError: Trigger parsing error: Module 'grpc' not found

I'm currently working on setting up an Angular4 application with Server Side Rendering (SSR) using Angular Universal and Firebase Cloud Functions. While the application works smoothly with ng serve, I encountered an issue after building the app and s ...

What is the best way to navigate through a webpage to find a specific folder and show its contents on the page?

My goal is to design a webpage where users can browse their computer for a specific folder, select it, and have its content displayed on the webpage. I am fairly new to creating pages, but I want to develop a platform where you can easily find and view f ...

Custom property fallback values do not function properly with CSS Variables

I defined a custom property in the :root selector as shown below, but for some reason my color is not rendering correctly. Can someone please help me identify what I am doing wrong? :root { --color-primary: var(--color-primary, #ffc107); } body { ...