如何在Bootstrap导航栏中的标志旁添加2个文本?

3
我正在使用Bootstrap,并尝试通过Navbar组件实现这种外观。

achieve this look

我试过使用导航栏图像和文本代码,但是文本只会在一行中继续。我尝试添加一个换行符,但是文本会出现在标志下面。它会看起来像这样。

enter image description here

这是我遵循的代码片段:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<nav class="navbar bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">
      <img src="    https://getbootstrap.com/docs/5.2/assets/brand/bootstrap-logo-shadow.png" alt="" width="70" height="70" class="d-inline-block align-text-top">
      Bootstrap <br> subheading
    </a>
  </div>
</nav>


将两个标题都包裹在一个“div.row”中。 - OMi Shah
2个回答

1

试试这个:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"/>

<nav>
  <div class="container-fluid">
    <div class="d-flex flex-row">
      <a class="navbar-brand navbar" href="#">
        <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTi65_HIy_en0R9pg-vjBsO3Fi2CFbJ96MtKdGIGjrlXw&s" alt="" width="100">
        <div class="d-flex flex-column p-2 pt-0 pb-0">
          <h1 class="mb-1">Title</h1>
          <p class="mb-1">Subheading</p>
        </div>
      </a>
    </div>
  </div>
</nav>


1
subheading 包含在 span 中,并添加 position:relative 以从左侧和顶部控制它。

nav .navbar-brand span{
  position:relative;
  top:30px;
  left:-90px;
  color:red;
 }
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
  
    <nav class="navbar bg-light">
      <div class="container-fluid">
        <a class="navbar-brand" href="#">
          <img src="    https://getbootstrap.com/docs/5.2/assets/brand/bootstrap-logo-shadow.png" alt="" width="70" height="70" class="d-inline-block align-text-top">
          Bootstrap <span> subheading </span>
        </a>
      </div>
  </nav>
  


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接