Html 如何更改导航栏上的突出显示颜色,将单个网页向下滚动到不同的部分

Html 如何更改导航栏上的突出显示颜色,将单个网页向下滚动到不同的部分,html,css,Html,Css,我正在尝试建立一个包含不同部分(主页、简历、联系人等)的实践档案/简历网页。我的固定导航栏已经高亮显示了你所在网页的哪个部分,但我想更改高亮显示的颜色。我尝试了很多不同的解决方案来解决这个问题,但由于某种原因,没有一个有效 我的代码当前为: <!DOCTYPE html> <html> <head> <title>Webpage</title> <meta charset="utf-8"> <meta na

我正在尝试建立一个包含不同部分(主页、简历、联系人等)的实践档案/简历网页。我的固定导航栏已经高亮显示了你所在网页的哪个部分,但我想更改高亮显示的颜色。我尝试了很多不同的解决方案来解决这个问题,但由于某种原因,没有一个有效

我的代码当前为:

<!DOCTYPE html>
<html>
<head>
  <title>Webpage</title>
  <meta charset="utf-8">
  <meta name="description" content="A portfolio of my work.">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <html lang="en-US">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet" type="text/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;
  }

  nav{
    background-color: black;
    color: red;
  }

  ul{
    height: 70px;
  }

  li>a{
    text-align: center;
    height: 71px;
    width: 150px;
    color: white;
    font-family: bookman;
    font-size: 20px;
  }

  }

  .navbar-inverse {
    background-color: black !important;
  }

  .nav > li > a:hover,

  .nav > li > a:focus {
    background: #B22222;
    color: white;
  }

  #home {padding-top:80px;height:675px;color: #fff; background-color: #00bcd4;}
  #about {padding-top:80px;height:675px;color: #fff; background-color: #673ab7;}
  #portfolio {padding-top:80px;height:675px;color: #fff; background-color: #ff9800;}
  #resume {padding-top:80px;height:675px;color: #fff; background-color: #00bcd4;}
  #contact {padding-top:80px;height:675px;color: #fff; background-color: #00bcd4;}
  </style>
</head>
<body data-spy="scroll" data-target=".navbar" data-offset="50">

<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container-fluid">
    <p class="navbar-text" style="color: white; padding-top: 7px; font-family: Oswald; font-size: 22px;">Name</p>
    <div>
      <div class="collapse navbar-collapse" id="myNavbar">
        <ul class="nav navbar-nav navbar-right">
          <li><a href="#home" class="active">Home</a></li>
          <li><a href="#about">About</a></li>
          <li><a href="#portfolio">Portfolio</a></li>
          <li><a href="#resume">Resume</a></li>
          <li><a href="#contact">Contact</a></li>
        </ul>
      </div>
    </div>
  </div>
</nav>

<div id="home" class="container-fluid">
</div>
</div>
<div id="about" class="container-fluid">
  <h1>Section 2</h1>
  <p><a href="#">My resume can be found here</a></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>
  <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="portfolio" 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="resume" 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="contact" 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>

网页
身体{
位置:相对位置;
}
导航{
背景色:黑色;
颜色:红色;
}
保险商实验室{
高度:70像素;
}
李>a{
文本对齐:居中;
高度:71px;
宽度:150px;
颜色:白色;
字体系列:bookman;
字体大小:20px;
}
}
.导航条反转{
背景色:黑色!重要;
}
.nav>li>a:悬停,
.nav>li>a:聚焦{
背景:#B22222;
颜色:白色;
}
#主页{填充顶部:80px;高度:675px;颜色:#fff;背景色:#00bcd4;}
#关于{填充顶部:80px;高度:675px;颜色:#fff;背景色:#673ab7;}
#公文包{填充顶部:80px;高度:675px;颜色:#fff;背景色:#ff9800;}
#简历{填充顶部:80px;高度:675px;颜色:#fff;背景色:#00bcd4;}
#联系人{填充顶部:80px;高度:675px;颜色:#fff;背景色:#00bcd4;}
名称

第二节

尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏

尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏

第三节 尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏

尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏

第4节子菜单1 尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏

尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏

第4节子菜单2 尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏

尝试滚动此部分,并在滚动时查看导航栏!尝试滚动此部分,并在滚动时查看导航栏


您没有提供有用的资源,根据这些资源,我可以确切地告诉您该做什么。但是基于此模板,您需要更改以下CSS类的属性

.navbar-default .nav>li.active>a, .navbar-default .nav>li.active>a:focus {     
    color: #fdcc52!important;
    background-color: transparent;
}
参考此

简单的例子试试这个

$(文档).ready(函数(){
$(文档).on(“滚动”,onScroll);
//平滑卷轴
$('a[href^=“#“]”)。关于('click',函数(e){
e、 预防默认值();
$(文档)。关闭(“滚动”);
$('a')。每个(函数(){
$(this.removeClass('active');
})
$(this.addClass('active');
var target=this.hash,
菜单=目标;
$target=$(target);
$('html,body').stop().animate({
'scrollTop':$target.offset().top+2
},500,'swing',函数(){
window.location.hash=目标;
$(文档).on(“滚动”,onScroll);
});
});
});
函数onScroll(事件){
var scrollPos=$(document.scrollTop();
$('#菜单中心a')。每个(函数(){
var currLink=$(此);
var refElement=$(currLink.attr(“href”);
if(refElement.position().top scrollPos){
$(“#菜单中心ul li a”).removeClass(“活动”);
currLink.addClass(“活动”);
}
否则{
currLink.removeClass(“活动”);
}
});
}
body,html{
保证金:0;
填充:0;
身高:100%;
宽度:100%;
}
.菜单{
宽度:100%;
高度:75px;
背景色:rgba(0,0,0,1);
位置:固定;
背景色:rgba(4180,49,0.6);
-webkit过渡:所有0.3秒轻松;
-moz转换:所有0.3秒轻松;
-o-过渡:所有0.3秒的速度;
过渡:所有0.3秒缓解;
}
.灯光菜单{
宽度:100%;
高度:75px;
背景色:rgba(255、255、255、1);
位置:固定;
背景色:rgba(4180,49,0.6);
-webkit过渡:所有0.3秒轻松;
-moz转换:所有0.3秒轻松;
-o-过渡:所有0.3秒的速度;
过渡:所有0.3秒缓解;
}
#菜单中心{
宽度:980px;
高度:75px;
保证金:0自动;
}
#菜单中心{
利润率:15px0;
}
#菜单中心{
列表样式:无;
利润率:0.30px 0.0;
显示:内联;
}
.主动{
字体系列:'Droid Sans',衬线;
字体大小:14px;
颜色:#fff;
文字装饰:无;
线高:50px;
}
a{
字体系列:'Droid Sans',衬线;
字体大小:14px;
颜色:黑色;
文字装饰:无;
线高:50px;
}
#家{
背景颜色:灰色;
身高:100%;
宽度:100%;
溢出:隐藏;
背景图片:url(images/home-bg2.png);
}
#恢复{
背景图片:url(images/portfolio bg.png);
身高:100%;
宽度:100%;
}
#关于{
背景颜色:蓝色;
身高:100%;
宽度:100%;
}
#接触{
背景色:红色;
身高:100%;
宽度:100%;
}

  • jQuery(document).ready(function($) {
      $(window).scroll(function() {
        var scrollPos = $(window).scrollTop(),
            navbar = $('.navbar-default');
    
        if (scrollPos > 20) {
          navbar.addClass('change-color');
        } else {
          navbar.removeClass('change-color');
        }
      });
    });
    
    .navbar-inverse .navbar-nav>.active>a,
    .navbar-inverse .navbar-nav>.active>a:focus,
    .navbar-inverse .navbar-nav>.active>a:hover {
        background-color: red;
    }