简体   繁体   English

所选标题位于顶部导航栏的后面

[英]Selected Heading goes behind the Top navigation bar

Here is my code : Navigaton Bar Issue 这是我的代码: Navigaton Bar问题

     <header class="header">
        <div class="Topheading">
        </div>
        <div class="TopNavigation">
            <nav class="leftnav">
                <ul>
                    <li><a href="">Test1</a></li>
                    <li><a href="">Test1</a></li>
                    <li><a href="">Test1</a></li>
                    <li><a href="">Test1</a></li>
                    <li style="float:right">
                        <button class="fedbut">Send Feedback</button>
                    </li>
                </ul>
            </nav>

        </div>
    </header>

The Top navigation bar is fixed and when clicking on the right side navigation it selects the navigation items on the page as per the heading and the selected heading goes behind the Top navigation bar. 顶部导航栏是固定的,当单击右侧导航时,它将根据标题选择页面上的导航项目,并且所选标题位于顶部导航栏的后面。

At present... 现在...

在此处输入图片说明

But the selected heading should be below the top navigation bar. 但是所选标题应位于顶部导航栏下方

like this... 像这样...

在此处输入图片说明

Thanks in advance.. 提前致谢..

It happens because you are pointing to ex #1 anchor and browser scrolls to that point. 发生这种情况是因为您指向的是ex #1锚,并且浏览器滚动到了该点。 And because your navbar is fixed it covers part of the content. 而且由于导航栏是固定的,因此它涵盖了部分内容。 You can fix this using JS: 您可以使用JS修复此问题:

$(".cuntnav a").on("click", function(e){
  e.preventDefault();
  var section_id = $(this).attr("href");
  var section_offset = $(""+section_id).offset().top;

  window.scrollTo(0, section_offset-100);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM