【问题标题】:How to set the top of the page to underneath a top-fixed navbar?如何将页面顶部设置在顶部固定导航栏下方?
【发布时间】:2017-06-09 10:02:26
【问题描述】:

如果您转到this 页面。 然后单击侧导航栏,它会滚动到页面上的某个点。但是,我要跳转到的部分的标题隐藏在固定导航栏后面。如何设置让页面跳转到每个部分的标题可见的位置?

【问题讨论】:

  • 的顶部提供一些边距

标签: html css navbar


【解决方案1】:

不要使用<br>作为底部边距。

将此添加到您的样式表中:

body{
    margin-top: 50px;
}

或作为内联css:

<body style="margin-top: 50px;"> ...

然后您可以从主要内容和侧边栏中删除占位符

【讨论】:

    【解决方案2】:

    您可以在部分标题中添加一些 padding-top,或者移动您命名的锚点,例如:

    a[name] {
      position: relative;
      top: -40px;
    }
    

    【讨论】:

      【解决方案3】:

      我认为您在谈论实现类。在正文中给出#(num) 类名称,并在导航栏中的链接中通过#(num) 调用,这将重定向您想要的位置。为什么在锚标记中给出 name='1' 来代替 href?

      这是错误的方式

      <a name="1"></a>
      

      由于这种方法,您可以看到内容进入顶部栏。

      改为

      <div class="1">
          <h1>Computing Notes</h1>
      </div> 
      

      使用 href #value 从锚标记调用,如下所示:

      <a href="#1">Fundamentals of computer systems</a>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多