Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a button right of the breadcrumb elements in Bootstrap 4?

I have the following breadcrumbs in use:

<ol class="breadcrumb">
    <li class="breadcrumb-item">
      <a href="#">Home</a>
    </li>
    <li class="breadcrumb-item active">My Account</li>
</ol>

Now what I want is to insert a button on the same line as the breadcrumbs, but have it float: right, like:

Home  /  My Account    < ---------- Space goes here ---------- >    Button

I tried the following, but it doesn't work:

<ol class="breadcrumb">
    <li class="breadcrumb-item">
      <a href="#">Home</a>
    </li>
    <li class="breadcrumb-item active">My Account</li>

    <span style="float: right;">
      <li class="breadcrumb-item">
        <button class="btn btn-sm btn-success">
          Create New User
        </button>
      </li>
    </span>

</ol>

Also I tried to use the bootstrap class float-right with no result.

How could I place the button on the same line with the breadcrumbs but float it right? Also there should be no slash / between the last breadcrumb and the button.

like image 929
manifestor Avatar asked Apr 30 '18 19:04

manifestor


2 Answers

One solution would be to take the button out of the ol and position it absolutely. This would require you to wrap the ol and button in a container and set position:relative; on the container:

.nav-container {
  position:relative;
}
button {
  position:absolute;
  right:1rem;
  top:50%;
  transform:translateY(-50%);
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="nav-container">
  <ol class="breadcrumb">
      <li class="breadcrumb-item">
        <a href="#">Home</a>
      </li>
      <li class="breadcrumb-item active">My Account</li>
  </ol>
  <button class="btn btn-sm btn-success">Create New User</button>
</div>
like image 83
APAD1 Avatar answered Oct 29 '22 13:10

APAD1


Here's a simple approach using bootstrap 4 util classes:

<div class="breadcrumb d-flex justify-content-between align-items-center">
  <ol class="breadcrumb mb-0 p-0">
    <li class="breadcrumb-item"><a href="#">Home</a></li>
    <li class="breadcrumb-item active">My Account</li>
  </ol>

  <button class="btn btn-sm btn-success">Create New User</button>
</div>
like image 4
neerfri Avatar answered Oct 29 '22 13:10

neerfri