Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position Bootstrap button to right of nav tab? [duplicate]

I am using Bootstrap's tab component and I'm having trouble getting the blue Log In button flush to the right side of the nav-tabs. I tried all kinds of things, but obviously I'm not understanding why it won't get positioned where I want.

Here's an image of what I am trying to do:

enter image description here

HTML:

<section class="container">
  <ul class="nav nav-tabs pt-5">
    <li class="nav-item"><a class="nav-link active" href="#">Home</a></li>
    <li class="nav-item"><a class="nav-link" href="#">Data</a></li>
    <li class="nav-item">
      <button type="button" class="btn btn-primary ml-2">Log In</button>
    </li>
  </ul>
</section>

JSFIDDLE: https://jsfiddle.net/auov8ety/

like image 210
redshift Avatar asked Jan 25 '19 16:01

redshift


2 Answers

simply give ml-auto to the button

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<section class="container">
  <ul class="nav nav-tabs pt-5">
    <li class="nav-item"><a class="nav-link active" href="#">Home</a></li>
    <li class="nav-item"><a class="nav-link" href="#">Data</a></li>
    <li class="nav-item ml-auto">
      <button type="button" class="btn btn-primary ml-2">Log In</button>
    </li>
  </ul>
</section>

Fiddle: https://jsfiddle.net/0fep392h/

like image 178
Nisharg Shah Avatar answered Oct 14 '22 11:10

Nisharg Shah


You can just use class ml-auto (Read Bootstrap Spacing for more info) on the nav-item that wraps the button:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

<section class="container">
  <ul class="nav nav-tabs pt-5">
    <li class="nav-item">
      <a class="nav-link active" href="#">Home</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#">Data</a>
    </li>
    <li class="nav-item ml-auto">
      <button type="button" class="btn btn-primary ml-2">Log In</button>
    </li>
  </ul>
</section>
like image 43
Shidersz Avatar answered Oct 14 '22 12:10

Shidersz