Bootstrap: 导航栏中的文本

根据 Bootstrap 文件,我应该能够“在一个 <p>标签包装字符串的正确领导和颜色。”当我这样做时,在 navbar之下的任何级别上,它都不会继承任何 navbar类。将字符串包装在 <a>标记中会呈现它,但它不应该是一个锚。

我要呈现的字符串是 "Logged in as ... "

66680 次浏览

You have to include a class along with your p tag inside of your navbar, like so:

<p class="navbar-text">Logged in as</p>

This was fixed in issue 2799.

I had to add <span class="navbar-text"> for the format to level with the anchor tags.

None of these answers or comments worked for me (latest one was 6+ years old), but what worked for me was the following:

  1. I had to use the <span> tag, not <p>
  2. I had to include the "nav-item" class on my list element itself

My final working code looks like this:

<li class="nav-item"><span class="navbar-text"><h5>\{\{first_name}}</h5></span></li>

Take my word for it, but the word "Sally" below does not change to hyperlink when hovered.

enter image description here