锚点跳转偏移位置(当顶部导航设置固定定位时挡住锚点区内容时)

29 篇文章 0 订阅

设置虚锚点

<a name="index" style=" position: relative;top: -80px;display: block;height: 0;overflow: hidden;"></a>

 

<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>aaaaaaaaaa</title>
 
    <style>
        * {
            margin: 0;
            padding: 0;
        }
 
        .nav {
            width: 70%;
            height: 80px;
            margin: 0 auto;
            background: pink;
            text-align: 80px;
            position: fixed;
            top: 0;
            z-index: 99;
        }
 
        .index {
            width: 100%;
            background: lightseagreen;
            ;
            height: 900px;
        }
 
          .concent{
            width: 100%;
            background: red;
            height: 900px;
        }
 
        .about-us {
            width: 100%;
            background: yellow;
            height: 900px;
        }
      
    </style>
</head>
 
<body>
 
    <!-- 固定导航栏 -->
    <div class="nav">
        <a href="#index" class="font-title font-active">首页</a>
        <a href="#concent" class="font-title">内容</a>
        <a href="#about-us" class="font-title">关于我们</a>
    </div>
 
    <div class="kong" style="height: 80px;width: 100%"></div>
    <div class="main-description">
 
        <!-- 设置暗锚点 -->
        <a name="index" style=" position: relative;top: -80px;display: block;height: 0;overflow: hidden;"></a>
        <!-- 真实锚点显示地方 -->
        <div class="index">首页</div>
 
        <a name="concent" style=" position: relative;top: -80px;display: block;height: 0;overflow: hidden;"></a>
        <div class="concent">内容</div>
 
        <a name="about-us" style=" position: relative;top: -80px;display: block;height: 0;overflow: hidden;"></a>
        <div class="about-us"><span>关于我们</span></div>
       
        <div class="kong" style="height: 80px;width: 100%"></div>
    </div>
 
</body>
 
</html>

 

 

如果是跨页面跳转这样就可

     <a href="a.html#index" class="font-title font-active">首页</a>
        <a href="a.html#concent" class="font-title">内容</a>
        <a href="a.html#about-us" class="font-title">关于我们</a>
    </div>

 

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值