如何更改导航栏中的文本颜色?

时间:2019-08-06 15:50:33

标签: html twitter-bootstrap bootstrap-4

我尝试使用推荐的引导程序4导航栏样式之一。我将代码粘贴到项目中,并且一切正常。唯一的问题是我已将背景颜色从深色更改为白色。由于导航栏中的文字不可见。我尝试了许多方法来将文本颜色更改为黑色,以便可以看到文本,但是它不起作用,而且我不知道如何将文本颜色从白色更改为黑色。

我尝试在无法正常运行的导航栏类中添加text-black类。

感谢您的帮助。

<!-- Navigation -->
<section id="navigation">
    <nav class="navbar navbar-expand-lg navbar-dark bg-white static-top text-black">
        <div class="container">
            <a class="navbar-brand" href="#">
                <img src="images/logo_5_150x60.png" alt="">
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarResponsive">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="#">Home
                            <span class="sr-only">(current)</span>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">About</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Services</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</section>

2 个答案:

答案 0 :(得分:1)

只需在#navigation *中添加一些CSS,然后使用color设置颜色即可。

#navigation * {
  color: red;
}
<!-- Navigation -->
<section id="navigation">
  <nav class="navbar navbar-expand-lg navbar-dark bg-white static-top text-black">
    <div class="container">
      <a class="navbar-brand" href="#">
        <img src="images/logo_5_150x60.png" alt="">
      </a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
      <div class="collapse navbar-collapse" id="navbarResponsive">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item active">
            <a class="nav-link" href="#">Home
                            <span class="sr-only">(current)</span>
                        </a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">About</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Services</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Contact</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>
</section>

希望这会有所帮助

答案 1 :(得分:1)

navbar-dark元素上的<nav>类是一种设置文本颜色的类。 使用浅背景色时,将navbar-dark更改为navbar-light

文档:https://getbootstrap.com/docs/4.3/components/navbar/#color-schemes

<!-- Navigation -->
<section id="navigation">
    <nav class="navbar navbar-expand-lg navbar-light bg-white static-top text-black">
        <div class="container">
            <a class="navbar-brand" href="#">
                <img src="images/logo_5_150x60.png" alt="">
            </a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarResponsive">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="#">Home
                            <span class="sr-only">(current)</span>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">About</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Services</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact</a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
</section>