Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 751
Ad Rienks Avatar asked Nov 29 '22 22:11

Ad Rienks


2 Answers

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

like image 166
Zim Avatar answered Dec 04 '22 10:12

Zim


If you put everything inside a Bootstrap column, it works as expected:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    
<div class="container">
    <div class="row">
        <div class="col-12">
            <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>
        </div>
    </div>
</div>
like image 36
WebDevBooster Avatar answered Dec 04 '22 11:12

WebDevBooster