Bootstrap 如何防止引导程序按钮文本换行?

iovurdzv  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(278)

我想用bootstrap创建一个导航栏,但我一直在努力让按钮看起来更漂亮。由于某种原因,在按钮文本中插入空格后,bootstrap在两个单词之间添加了新行。这看起来很糟糕,我该如何修复它呢?用这段代码我得到了:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg bg-light">
  <div class="container-fluid">
    <form class="d-flex" role="search">
      <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-primary" type="submit">Test</button>
    </form>
  </div>
</nav>

然而,在按钮文本内添加空格后,我得到了以下结果:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg bg-light">
  <div class="container-fluid">
    <form class="d-flex" role="search">
      <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-primary" type="submit">T est</button>
    </form>
  </div>
</nav>

我如何使它在一行中,即使有空格?

ax6ht2ek

ax6ht2ek1#

引导程序的容器是flexbox元素。这意味着按钮将折叠以占用其最小的水平空间。您可以使用文本换行实用程序类来防止这种情况。

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg bg-light">
  <div class="container-fluid">
    <form class="d-flex" role="search">
      <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-primary text-nowrap" type="submit">T est</button>
    </form>
  </div>
</nav>

相关问题