Bootstrap 4 类 form-inline 和 float-sm-right 不能合并吗?

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>

这是使用 Bootstrap v4.alpha2 的示例。 (我已经发现应该使用 float- 而不是 pull- :(

但在Bootstrap v4.0.0 中不起作用;我使用 bower 安装的。

如何使表格位于右边缘?解决方法是什么? 还是类不能合并?

我必须说:Bootstrap 假装使样式更容易,但对我来说,情况越来越糟 -- 版本之间的变化如此之多:-(

编辑:我会给你整个代码块:

<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>

希望与 bootstrap v4.0.0 兼容!

如果您将所有内容都放在 Bootstrap 列中,它会按预期工作:

<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>

Bootstrap 4 Navbar 是 flexbox,因此浮动不能用于对齐。最简单的方法是使用 auto-margins 将表格向右推。只需使用 ml-automargin-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>

相关问题: