【问题标题】:How to apply or change color on navbar (menu) items如何在导航栏(菜单)项目上应用或更改颜色
【发布时间】:2017-12-15 05:16:18
【问题描述】:

我想弄清楚如何在我的导航栏右侧获取图像。一旦它被折叠,我的导航栏右侧也会有一个图像。

另外,我不知道如何在滚动时将导航栏固定在页面顶部。我试过导航栏固定顶部,但无济于事。

我正在使用引导程序

这是我的代码..

.navbar-default .navbar-toggle .icon-bar {
  background-color: white;
}

.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
  background-color: transparent !important;
}

.navbar-toggle {
  margin-top: 2em;
  border: none;
  color: white;
}

.navbar-fixed-top {
  position: static !important;
}

.navbar-nav,
.navbar-nav li,
.navbar-nav li a {
  text-align: right;
  font-family: "Montserrat";
  color: white;
}

.navbar.navbar-default .navbar-collapse {
  border: none;
  box-shadow: none;
}

.navbar-fixed-top {
  margin-right: 0em;
  margin-top: 1em;
}

.navbar {
  background-color: transparent;
  background: transparent;
  border-color: transparent;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="container">
  <nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
      <div class="navbar-header ">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbarNav">
                      <span class="sr-only">Toggle navigation</span>
                      <span class="icon-bar"></span>
                      <span class="icon-bar"></span>
                      <span class="icon-bar"></span>
                    </button>
      </div>
      <div id="navbarNav" class="navbar-collapse collapse ">
        <br/><br/>
        <ul class="nav navbar-nav navbar-right ">
          <li><a href="#">ABOUT</a></li>
          <li><a href="#">SERVICES</a></li>
          <li><a href="#">CONTACT</a></li>
          <li><a href="#">CALCULATORS</a></li>
        </ul>
      </div>

    </div>
  </nav>
</div>

非常感谢您的任何帮助,非常感谢!

【问题讨论】:

  • 我不明白你在右边的图片是什么意思。放置在?在导航栏上?
  • 如果任何解决方案对您有所帮助,您可以对其进行评分或标记为已接受。

标签: html css twitter-bootstrap-3


【解决方案1】:

可能是因为 bootstrap 的 CSS 是overriding your own custom CSS。不过,有一个简单的解决方法,您可以实现 your own ID or class on the navbar-nav,正如我在下面使用 ID "links" 演示的那样,并将 CSS 应用到链接上。

.navbar-default .navbar-toggle .icon-bar {
  background-color: white;
}

.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
  background-color: transparent !important;
}

.navbar-toggle {
  margin-top: 2em;
  border: none;
  color: white;
}

.navbar-fixed-top {
  position: static !important;
}


#links a {
  text-align: right;
  font-family: "Montserrat";
  color: red;
}

.navbar.navbar-default .navbar-collapse {
  border: none;
  box-shadow: none;
}

.navbar-fixed-top {
  margin-right: 0em;
  margin-top: 1em;
}

.navbar {
  background-color: transparent;
  background: transparent;
  border-color: transparent;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="container">
  <nav class="navbar navbar-default navbar-fixed-top">
    <div class="container-fluid">
      <div class="navbar-header ">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbarNav">
                      <span class="sr-only">Toggle navigation</span>
                      <span class="icon-bar"></span>
                      <span class="icon-bar"></span>
                      <span class="icon-bar"></span>
                    </button>
      </div>
      <div id="navbarNav" class="navbar-collapse collapse ">
        <br/><br/>
        <ul class="nav navbar-nav navbar-right" id="links">
          
          <li><a href="#">ABOUT</a></li>
          <li><a href="#">SERVICES</a></li>
          <li><a href="#">CONTACT</a></li>
          <li><a href="#">CALCULATORS</a></li>
          
        </ul>
      </div>

    </div>
  </nav>
</div>

【讨论】:

    【解决方案2】:

    固定页眉、页面滚动和导航项颜色在滚动时发生变化。

    <!DOCTYPE html>
    <html>
    <head>
      <title>Page Scroll Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <style>
      body {
          position: relative; 
      }
      #section1 {padding-top:50px;height:500px;color: #fff; background-color: #1E88E5;}
      #section2 {padding-top:50px;height:500px;color: #fff; background-color: #673ab7;}
      #section3 {padding-top:50px;height:500px;color: #fff; background-color: #ff9800;}
      #section41 {padding-top:50px;height:500px;color: #fff; background-color: #00bcd4;}
      #section42 {padding-top:50px;height:500px;color: #fff; background-color: #009688;}
      </style>
    </head>
    <body data-spy="scroll" data-target=".navbar" data-offset="50">
    
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>                        
          </button>
          <a class="navbar-brand" rel="home" href="#" title="Buy Sell Rent Everyting">
                    <img style="max-width:100px; margin-top: -7px;"
                         src="//www.google.com/favicon.ico">
                </a>
        </div>
        <div>
          <div class="collapse navbar-collapse" id="myNavbar">
            <ul class="nav navbar-nav">
              <li><a href="#section1">Section 1</a></li>
              <li><a href="#section2">Section 2</a></li>
              <li><a href="#section3">Section 3</a></li>
              <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Section 4 <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li><a href="#section41">Section 4-1</a></li>
                  <li><a href="#section42">Section 4-2</a></li>
                </ul>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </nav>    
    
    <div id="section1" class="container-fluid">
      <h1>Section 1</h1>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="section2" class="container-fluid">
      <h1>Section 2</h1>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="section3" class="container-fluid">
      <h1>Section 3</h1>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="section41" class="container-fluid">
      <h1>Section 4 Submenu 1</h1>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    <div id="section42" class="container-fluid">
      <h1>Section 4 Submenu 2</h1>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
      <p>Try to scroll this section and look at the navigation bar while scrolling! Try to scroll this section and look at the navigation bar while scrolling!</p>
    </div>
    
    </body>
    </html>

    【讨论】:

      猜你喜欢
      • 2019-01-21
      • 1970-01-01
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      • 2016-06-16
      • 2020-11-09
      • 2012-09-11
      • 2014-07-17
      相关资源
      最近更新 更多