如何使导航栏透明,然后使用bootstrap 3更改颜色.(粘贴)

How do you make it so the navbar is transparent then changes color using bootstrap 3. (Affix)

本文关键字:颜色 粘贴 bootstrap 导航 何使 透明 然后      更新时间:2023-09-26

我已经试着找到如何做到这一点一周了,但一直无法做到。我的html导航栏是这样的。

<div class="maincontainer">
<!--Navbar-->
<div data-spy="affix" data-offset-top="60" data-offset-bottom="200">
  <div class="navbar navbar-default navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header" >
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">Pixoweb</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li class="active"><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">Examples<b class="caret"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Example 1</a></li>
                        <li><a href="#">Example 2</a></li>
                        <li><a href="#">Example 3</a></li>
                        <li><a href="#">Example 4</a></li>
                    </ul>
                </li>
                <li><a href="#contact" data-toggle="modal">Contact</a></li>
            </ul>
        </div>
    </div>
</div>

Js

    $('#myAffix').affix({
  offset: {
    top: 100,
    bottom: function () {
      return (this.bottom = $('.footer').outerHeight(true))
    }
  }
})

css

      .affix {
    position: fixed !important;
    top: 0 !important;
    width: 100% !important;
    background-color: #957595 !important;
}

到目前为止,这使得导航栏位于上下文和图像后面。如果有人能帮我,我会很高兴的

Navbar没有落后于文本/图像,它已经通过bootstrap词缀进行了3d转换,看起来像是落后了。我假设您希望在固定(粘贴)导航条时更改其背景颜色。您可以使用以下CSS。注意:您不需要JavaScript。

.affix .navbar-default {
    position: fixed !important;
    top: 0 !important;
    width: 100% !important;
    background-color: #957595 !important;
}
.affix {
    width: 100% !important;
}

我也很难在图像后面显示菜单,我通过在导航类中添加"z-index:1;"来解决这个问题。例如:样式表中的.navbar反转

.navbar-default {
  background-color: #201f1f;
  border-color: #f47d20;
  border-bottom:#f47d20 5px solid;
  padding-bottom:0px;
  z-index: 1;
}