css 锚点 链接

<!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>Document</title>

</head>

<style>

@charset "utf-8";

/* CSS Document Download by http://www.codefans.net*/

.gray {

-webkit-filter: grayscale(100%);

-moz-filter: grayscale(100%);

-ms-filter: grayscale(100%);

-o-filter: grayscale(100%);

filter: grayscale(100%);

filter: gray;

}

/* reset */

body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, p , form, fieldset, legend, input, button, textarea, th, td {

margin:0;

padding:0;

}

table {

border-collapse:collapse;

border-spacing:0;

}

fieldset, img {

border:0;

}

ul,li {

list-style:none;

}

body {

background: #f1f1f1;

color: #666;

font:12px/1.7 Helvetica,Arial,Tahoma,sans-serif,"\5B8B\4F53";

}

.row:after {

clear:both;

content:'\0020';

display:block;

height:0;

}

.row {

zoom:1;

}

/*链接颜色*/

a,button{outline:none; /*移除虚线框 IE8,FF有用*/ hide-focus: expression(this.hideFocus=true); /*IE6、IE7*/}

a{

color:#999;

text-decoration:none;

}

a:hover{

color:#be0000;

text-decoration: underline;

}

.fst{

font-family: "\5B8B\4F53";

}

h1,h2,h3,h4,h5,h6{font-family:\5FAE\8F6F\96C5\9ED1; font-size: 16px;}

/* end reset */

.row{

width:1000px;

margin:0 auto;

}

/*模板头部,所有专题页面公用*/

.index_nav{width:575px; height: 70px; margin: 0 auto; padding-left: 5px; background: #fff;}

.index_nav li{width: 115px; height: 70px; float: left;}

.index_nav li a{display: block; float: left; width: 70px;height: 70px; background:url(../images/index_nav.gif) 0 0 no-repeat; text-align: center; color: #e02800;}

.index_nav li a i{display: block; padding-top: 12px; height: 22px; line-height: 22px;}

.index_nav li a strong{font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 24px; display: block; height: 30px; line-height: 20px;}

.index_nav li a:hover{background-position: 0 -70px; color: #fff; text-decoration: none;}

.h15{height: 15px; overflow: hidden;}

.mainpage{width: 1000px; height:1000px;}

h2{font-size: 24px; text-align: center; color: #333; font-weight: bold;}

.mainpage p{width: 650px; margin: 0 auto; color: #fff; font-size: 16px; padding: 50px 0 50px;}

.mainpage1{background: #fe6400;}

.mainpage2{background: #be0000;}

.mainpage3{background: #ccc;}

.mainpage4{background: #0093dd;}

.mainpage5{background: #a8cf33;}

*html{background-image:url(about:blank);background-attachment:fixed;}/*低版本浏览器防止抖动的,必须有*/

#tbox{width:30px; height:200px; float:right; position:fixed; display: none;

_position:absolute;

_bottom:auto;

_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));

_margin-bottom:50px;

}/*这个只能改宽高其他的不要修改,需要滚动的内容都要放在这个div里面*/

.taoba{display:block; background:#c2c2c2; width:30px; height:30px; margin-bottom:4px;text-align: center; color: #fff; line-height: 30px; overflow: hidden;cursor:pointer}

.taoba:hover{background:#ff4200; text-decoration: none; color: #fff;}

#gotop{display:block; width:30px; height:30px; text-indent:-9999px; overflow: hidden; color: #fff; background:url(../images/top_icon.gif) no-repeat; position:absolute; display:none; cursor:pointer} /*这个样式随便改,必须有position:absolute; */

#gotop:hover{background-position: 0 -30px;}

</style>

<body>

    <div class="indexnav_wrap">

     <ul class="index_nav">

        <li><a href="javascript:void(0)" title="1"><i>活动</i><strong>1</strong></a></li>

        <li><a href="javascript:void(0)" title="2"><i>活动</i><strong>2</strong></a></li>

        <li><a href="javascript:void(0)" title="3"><i>活动</i><strong>3</strong></a></li>

        <li><a href="javascript:void(0)" title="4"><i>活动</i><strong>4</strong></a></li>

        <li><a href="javascript:void(0)" title="5"><i>活动</i><strong>5</strong></a></li>

     </ul>

    </div>

    <div class="h50"></div>

    <div class="row" id="main">

     <h2 id="index_1">这是第一个活动页</h2>

    

     <div class="mainpage mainpage1">

        </div>

    

    </div>

    <div class="h15"></div>

    <div class="row">

     <h2 id="index_2">这是第二个活动页</h2>

    

     <div class="mainpage mainpage2">

    

        </div>

    

    </div>

    <div class="h15"></div>

    <div class="row">

     <h2 id="index_3">这是第三个活动页</h2>

    

     <div class="mainpage mainpage3">

    

        </div>

    

    </div>

    <div class="h15"></div>

    <div class="row">

     <h2 id="index_4">这是第四个活动页</h2>

    

     <div class="mainpage mainpage4">

    

        </div>

    

    </div>

    <div class="h15"></div>

    <div class="row">

     <h2 id="index_5">这是第五个活动页</h2>

    

     <div class="mainpage mainpage5">

    

        </div>

    

    </div>

    <div id="tbox"><!-- 这个必须有 id="tbox"-->

        <a class="taoba" href="javascript:void(0)" title="1">1</a>

        <a class="taoba" href="javascript:void(0)" title="2">2</a>

        <a class="taoba" href="javascript:void(0)" title="3">3</a>

        <a class="taoba" href="javascript:void(0)" title="4">4</a>

        <a class="taoba" href="javascript:void(0)" title="5">5</a>

        <a id="gotop" href="javascript:void(0)" title="回到顶部">回到顶部</a> <!-- 这个也是id="gotop" -->

    </div>

    </div>

    </body>

    

</html>

<script src="./jQuery_v1.12.4.js"></script>

<script type="text/javascript">

    jQuery(document).ready(function($) {

     $(".index_nav li a").click(function(event) {

        var index=this.title

        var id='#'+'index_'+index

     $("html,body").animate({scrollTop: $(id).offset().top}, 1000);

     });

     $(".taoba").click(function(event) {

        var index=this.title

        var id='#'+'index_'+index

     $("html,body").animate({scrollTop: $(id).offset().top}, 1000);

     });

     function a(x,y){

     l = $('#main').offset().left;

     w = $('#main').width();

     $('#tbox').css('left',(l + w + x) + 'px');

     $('#tbox').css('bottom',y + 'px');

         }//获取#tbox的div距浏览器底部和页面内容区域右侧的距离函数#main为页面的可视宽度

         $(function() {

             $(window).scroll(function(){

             t = $(document).scrollTop();

             if(t>500){

                $('#tbox').show();

             }else{

                $('#tbox').hide();

             }

             if(t > 50){

                 $('#gotop').fadeIn('slow');

             }else{

                 $('#gotop').fadeOut('slow');

             }

         })

             a(10,100);//#tbox的div距浏览器底部和页面内容区域右侧的距离

             $('#gotop').click(function(){

                 $('body,html').animate({

                     scrollTop: 0

                 },

                 800);//点击回到顶部按钮,缓懂回到顶部,数字越小越快

                 return false;

             })

         });

    });

</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTML锚点是指一个页面中的特殊链接,它可以跳转到页面内的任意位置,而不是跳转到另一个页面。锚点是通过在HTML中设置ID属性来实现的。CSS锚点则是通过CSS样式来设置锚点的样式和行为。 首先,你需要在HTML中设置一个锚点,可以使用以下代码: ```html <a id="myAnchor">这是我的锚点</a> ``` 在上面的代码中,我们使用了一个`<a>`标签,并设置了一个`id`属性为`myAnchor`。这个`id`属性可以是任何你想要的名称,但它必须是唯一的。 接下来,你需要在页面中设置一个链接,让它可以跳转到这个锚点。可以使用以下代码: ```html <a href="#myAnchor">跳转到我的锚点</a> ``` 在上面的代码中,我们使用了一个`<a>`标签,并设置了一个`href`属性为`#myAnchor`。这个`#myAnchor`表示我们要跳转到页面中的ID为`myAnchor`的元素。 现在,我们来讲一下CSS锚点的使用。 CSS锚点可以让我们自定义锚点的样式和行为。我们可以使用以下CSS代码来设置锚点的样式: ```css a:link { color: blue; text-decoration: none; } a:hover { color: red; text-decoration: underline; } ``` 在上面的代码中,我们设置了两个CSS选择器。第一个选择器`a:link`表示当链接未被访问时的样式,我们设置了链接的颜色为蓝色,并且去掉了下划线。第二个选择器`a:hover`表示当鼠标悬停在链接上时的样式,我们设置了链接的颜色为红色,并且添加了下划线。 通过设置CSS锚点,我们可以让我们的链接看起来更加美观和易于使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值