Issue with positioning of Bootstrap Nav item on the right side

I've been struggling to get my nav-items in my ul to float right. Despite trying various methods, including those outlined in this comprehensive answer: Bootstrap 4 align navbar item to the right

Unfortunately, the nav item remains stubbornly stuck on the left.

It's starting to feel like I'm overlooking something obvious here. The recently added div class that wraps the list items doesn't appear to have any impact on the behavior of the list item. Just to clarify, all my attempts so far have been made without these div tags.

Is there something glaringly wrong that anyone can spot in my code?

    .navbar-default {
      background-color: white;
    }
    
    .navbar {
      display: flex;
      min-height: 50px;
      border-bottom: 1px solid black;
      align-items: center;
      margin-bottom: 0;
    }
    
    
    .profile-dropdown {
      border-radius: 50%;
      height: 50px;
      width: 50px;
      border: 1px solid black;
      object-fit: cover;
    }
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
    
      <a class="navbar-brand" href="#">Equilibrium</a>
    <!-- If the user is logged in, display a profile icon. -->
    
      <ul class="nav navbar-nav mr-auto">
    
     
          <li class="nav-item">
            <a>
              <img src="" class="profile-dropdown" alt="">
            </a>
          </li>
      
          <li class="nav-item" >
            <img src="/assets/glyphicons/user.png" class="profile-dropdown" alt="">
          </li>
   
    
      </ul>
    
    </nav>

I would really appreciate any assistance with this issue. Thank you.

Answer №1

If you're looking to align items to the right, remember to use ml-auto instead of mr-auto. This will ensure that all items are properly aligned on the right side.

Answer №2

Here is a sample of a functional navbar designed for Bootstrap 4. This example will guide you in the right direction. Feel free to reach out with any questions in the comments section.

The mr-auto class is effectively utilized here, shifting the content on the right side to the opposite end. (where mr-auto = "margin-right: auto")

Below is the code snippet:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">


<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#">Navbar</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#">Link</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    Dropdown
                </a>
                <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                    <a class="dropdown-item" href="#">Action</a>
                    <a class="dropdown-item" href="#">Another action</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#">Something else here</a>
                </div>
            </li>
            <li class="nav-item">
                <a class="nav-link disabled" href="#">Disabled</a>
            </li>
        </ul>
        <a class="navbar-brand" href="#">
            <p><i class="fa fa-user" aria-hidden="true"></i></p>
        </a>
    </div>
</nav>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

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

Using javascript, what is the best way to clear a text field with a specific condition?

When I clear the text field #t1, I expect text field #d1 to also clear. However, the last two lines of code do not achieve this result. function utl() { var tField = document.getElementById('t1'); var dField = document.getElementById(&a ...

Troubleshooting border problems with Bootstrap 3 tables

Recently, I encountered a problem with the Bootstrap 3 table-bordered where the right border was not showing up. Below is the code snippet of my table: <table class="table table-bordered table-hover"> ... </table> Upon inspecting the table vi ...

What is the best method for incorporating a unique style to a v-dialog component in Vuetify following the most recent update?

I'm currently working on a project using vuetify, and I am facing an issue while trying to add a custom class to a v-dialog component. I have tried searching for information on how to do this, but it seems that the prop "content-class" has been deprec ...

CSS tables are not properly recognizing the class values within the table

This is the CSS I am working with: table { margin: 10px 0 20px 0; width: 100%; text-align: center; } table th { color: #38A4FC; padding-top: 5px; background-color: #f9f9f9; width: 200px; height: 30px; border: 1px solid #d7d7d7; border-bottom: none; } ...

Achieving a horizontal alignment of Bootstrap cards using ReactJS

I have been utilizing Bootstrap 4 to present data to the user. Now, I am considering displaying the data in columns and rows. The frontend is built with ReactJS and it retrieves data from the backend response. Currently, I have successfully displayed the ...

Access the second argument in the method `document.getElementById("box5" && "box14")`

I need help with a script that should set the variable trouve_coupable to true only if both box 5 and box 14 are checked on my HTML page. However, no matter what I do on the page, whenever box 14 (="case14") is checked, it always returns true whe ...

I am having trouble debugging the Twitter Bootstrap v4-alpha grid. The col-sm-offset-* class doesn't seem to be

Something has been altered somewhere, causing col-sm-offset-*s to stop functioning entirely. For instance, when attempting to split the screen in half and only display content on the right side, I typically would use: <div class="container"> < ...

Half screen layout using Bootstrap's grid system

Can you create two rows with four columns each, occupying 50% of the screen's height? Sample Bootstrap code for achieving this layout: <div class="row"> <div class="col-md-3">.col-md-3</div> <div class="col-md-3">.col ...

Arrange text boxes within a form and table to be in alignment with the labels

https://i.stack.imgur.com/MFQnD.png I'm facing difficulty aligning checkboxes with labels within a form and a table. Despite reviewing various answers and websites, I am still unable to achieve the desired alignment. How to consistently align check ...

The appearance of the drop-down menu in IE is not the same as in other

I have implemented css bootstrap 3.2.0 on my website. However, I have noticed some discrepancies when viewing the site in Internet Explorer. The menu options have a thick black border and the dropdown menu button appears different compared to other browse ...

Update the message displayed in MUI DataTables when there are no matching records found

Whenever the data array in my MUIDataTable is empty, a default message pops up stating: "Sorry, no matching records found". I'm looking to personalize this message and input my own text. Any assistance would be greatly appreciated. ...

Allowing users to navigate through a fixed content page using a scrolling menu, all without the need

On my webpage, I have integrated Google Maps. The layout is divided into a menu on the left and content on the right. I am looking to make the left side (menu) scrollable, while the right side (content, which includes the map) remains static without scrol ...

Conceal altered dropdown menus

I am working on a table that contains 3 rows, each with 3 select boxes. My goal is to hide the select box when a change occurs, insert a brief loader image for 250 milliseconds, and then display the select box with the selected option. For example, if I ch ...

The application has encountered an unexpected error and is currently unavailable

This is the code snippet for my MainActivity.java file. I am developing a simple LoginApp. However, when I try to run the app, it displays an "unfortunately stopped working ERROR..." message. package com.example.loginapp; import android.os.Bundle; import ...

A guide to retrieving hyperlinks from an HTML table with Selenium

I am currently working on a Java and Selenium code snippet like the one below: public static void main(String[] args){ WebDriver driver; DesiredCapabilities caps; caps = new DesiredCapabilities(); caps.setCapability(PhantomJSDriverService ...

Discovering the true width of an element using JavaScript

Hey there, I'm currently attempting to determine the exact width of a specific element and display an alert that shows this width. The code I am using is as follows: HTML Element <table cellspacing="1" cellpadding="5" style=";width:975px;border: ...

Initial button click fails to trigger onclick event

After researching and reading various articles on the issue, I have tried several solutions but nothing seems to work. The problem occurs when the button is clicked for the first time - nothing happens. It is only after clicking the button a second time th ...

Navigating to DIV position while rendering JSP

Is it possible to make the browser automatically scroll to a specific DIV location when loading a JSP page? The DIV could be placed anywhere on the page and has a unique identifier. I am aware that this can be achieved using Javascript/jQuery, but I speci ...

Issue with Bootstrap navigation bar extending webpage length beyond desired size

I recently constructed a website using the latest version of Bootstrap, commencing with the cover template. After swapping the navbar with one from the documentation, I noticed that the webpage now extends beyond the screen's length. At the end of the ...

Using jQuery in Yii: Detecting when a radio button loses its checked state

Here is the code regarding the issue at hand: <script> $(function(){ $('#widgetId-form input[name="valueType"]').change(function(){ if ($(this).is(":checked")) { console.log("enabling "+$(this).data("class") ...