0

I am not able to figure out this simple task. I need to place the button to the left side.

enter image description here

html

<body>

    <nav class="navbar navbar-dark fixed-top bg-info flex-md-nowrap p-0">

        <a class="navbar-brand col-md-2 mr-0" href="#">Web name</a>

        <button class="btn btn-primary btn-sm float-left">
            <span data-feather="toggle-left"></span>
        </button>

        <span class="text-nowrap" style="color:white; margin-right:20px;"><span data-feather="user"></span>username</span>

    </nav>
...
</body>
Muflix
  • 6,192
  • 17
  • 77
  • 153
  • 1
    The `navbar` class in Bootstrap 4 is a flex-box that attempts to space child elements evenly within the navbar with the rule `justify-content: space-between`. [This post](https://stackoverflow.com/questions/41513463/bootstrap-4-align-navbar-items-to-the-right) has an answer which should help! – Wrokar Apr 24 '18 at 16:57

1 Answers1

2

Replace float-left with mr-auto for auto right margin. This will make the button push back to the left.

<nav class="navbar navbar-dark fixed-top bg-info flex-md-nowrap p-0">
    <a class="navbar-brand col-md-2 mr-0" href="#">Web name</a>
    <button class="btn btn-primary btn-sm mr-auto">
        <span data-feather="toggle-left"></span>
    </button>
    <span class="text-nowrap" style="color:white; margin-right:20px;"><span data-feather="user"></span>username</span>
</nav>

https://www.codeply.com/go/SQD3e4YHMY


Related: Bootstrap NavBar with left, center or right aligned items

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624