<a>
链接时,定位点似乎错误,因为您无法看到标题部分。在我的情况下<h2>
。<a>
链接?像边框或像这样的东西...... 这是HTML代码:
<!-- Fixed navbar -->
<nav id="navbar" class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="page-scroll"><a href="#">Home</a></li>
<li><a class="page-scroll" href="#ark">Architektur</a></li>
<li><a class="page-scroll" href="#">Wohnen</a></li>
<li><a class="page-scroll" href="#ausstattung">Ausstattung</a></li>
<li><a class="page-scroll" href="#lage">Lage</a></li>
<li><a class="page-scroll" href="#">Galerie</a></li>
<li><a class="page-scroll" href="#kontakt">Kontakt</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<!-- === END NAV === -->
编辑:
答案 0 :(得分:0)
selected{
background-color: silver;
color: #fff;
}
var links = $(".page-scroll");
links.on('click',function(){
links.removeClass("selected");
$(this).addClass("selected");
});
&#13;
li{
list-style-type: none;
}
.page-scroll{
float:left;
padding:15px;
text-align: center;
background-color: black;
color: #fff;
}
.selected{
background-color: silver;
color: black;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav id="navbar" class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a class="page-scroll" href="#">Home</a></li>
<li><a class="page-scroll" href="#ark">Architektur</a></li>
<li><a class="page-scroll selected" href="#">Wohnen</a></li>
<li><a class="page-scroll" href="#ausstattung">Ausstattung</a></li>
<li><a class="page-scroll" href="#lage">Lage</a></li>
<li><a class="page-scroll" href="#">Galerie</a></li>
<li><a class="page-scroll" href="#kontakt">Kontakt</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
&#13;
然后,您需要在单击导航栏中的锚点时添加此类
答案 1 :(得分:0)
我不确切地知道你在第一个问题中的意思,但突出显示<a></a>
这里是代码:
HTML
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Clients</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
CSS
li{
padding: 8px;
}
a{
text-decoration: none;
color: #000;
}
a:hover, a:focus{
color: red;
text-decoration: none;
outline: none;
}
.active{
font-size: 30px;
color: red;
border-bottom: 5px solid red;
}
的jQuery
$(document).ready(function(){
$('a').click(function(){
$('a').removeClass("active");
$(this).addClass("active");
});
});
工作小提琴:
答案 2 :(得分:0)
对于问题1,解决方案是 - 将其添加到您的CSS文件中(可以取出3个第一行,因为它们只是我的评论):
/* FIXES problem:
Navbar hides initial content when jumping to in-page anchor #1768
https://github.com/twbs/bootstrap/issues/1768 */
*[id]:before {
display: block;
content: " ";
margin-top: -75px;
height: 75px;
visibility: hidden;
}