Can the Bootstrap 4 classes form-inline and float-sm-right not be combined?

Ad Rienks picture Ad Rienks · Mar 20, 2018 · Viewed 14.8k times · Source

HTML:

<form class="form-inline float-sm-right">
  <input type="text" class="form-control" placeholder="Search">
  <button class="btn btn-outline-success" type="submit">Search</button>
</form>

This is from an example using Bootstrap v4.alpha2. (I already found out that float- should be used, instead of pull- :(

But it does not work in Bootstrap v4.0.0; that I have installed using bower.

What is the solution, to get the form on the right edge? Or can the classes not be combined?

I must say: Bootstrap pretends to make styling easier, but for me, it is getting worse and worse -- so many changes between versions :-(

Edit: I will give you the whole code block:

<nav class="navbar navbar-expand-sm navbar-dark bg-dark" id="nav-main">
  <a class="navbar-brand" href="#">Navbar</a>
  <ul class="nav navbar-nav">
    <li class="nav-item">
      <a href="#" class="nav-link">Home <span class="sr-only">(current)</span></a>
    </li>
    <li class="nav-item">
      <a href="#" class="nav-link">Features</a>
    </li>
    <li class="nav-item">
      <a href="#" class="nav-link">Pricing</a>
    </li>
    <li class="nav-item">
      <a href="#" class="nav-link">About</a>
    </li>
  </ul>
  <form class="form-inline float-sm-right">
    <input type="text" class="form-control" placeholder="Search">
    <button class="btn btn-outline-success" type="submit">Search</button>
  </form>
</nav>

Hopefully, with everything bootstrap v4.0.0 compatible!

Answer

Zim picture Zim · Mar 20, 2018

The Bootstrap 4 Navbar is flexbox, so float won't work for alignment. The easiest method is to use auto-margins to push the form to the right. Just use ml-auto which is margin-left:auto;...

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

<nav class="navbar navbar-expand-sm navbar-dark bg-dark" id="nav-main">
  <a class="navbar-brand" href="#">Navbar</a>
  <ul class="nav navbar-nav">
    <li class="nav-item">
      <a href="#" class="nav-link">Home <span class="sr-only">(current)</span></a>
    </li>
    <li class="nav-item">
      <a href="#" class="nav-link">Features</a>
    </li>
    <li class="nav-item">
      <a href="#" class="nav-link">Pricing</a>
    </li>
    <li class="nav-item">
      <a href="#" class="nav-link">About</a>
    </li>
  </ul>
  <form class="form-inline ml-auto">
    <input type="text" class="form-control" placeholder="Search">
    <button class="btn btn-outline-success" type="submit">Search</button>
  </form>
</nav>

Related question:
Bootstrap 4 align navbar items to the right