使用锚点链接做出页面切换效果

锚点链接

1.锚点链接的使用

1.使用a标签应用 herf 属性,href 属性="#id名"

2.只要点击了超链接的对象就会跳到指定位置

2.利用锚点链接在同一个页面中的切换效果:
代码如下:

    <style>
        /* 清楚默认空隙 */
        *{
            margin: 0;
            padding: 0;
        }
        /* 清楚<a>标签的默认下划线样式 */
        a{
            text-decoration: none;
        }
        .big_box{
            width: 300px;
            height: 300px;
            /* 让盒子居中 */
            margin: 0 auto;
        }
        ul{
            /* 清除li前面的小圆点 */
            list-style: none;
            float: left;
            width: 100px;
            height: 300px;
            background-color: pink;
        }
        ul li{
            margin-top: 50px;
            text-align: center;
        }
        .small_box{
            width: 200px;
            height: 300px;
            /* 将大盒子溢出的部分隐藏 */
            overflow: hidden;
            float: left;
        }
        .small_box #one{
            width: 200px;
            height: 300px;
            background-color: rgb(197, 51, 75);
            /* 文字水平居中 */
            text-align: center;
            /* 文字垂直居中 */
            line-height: 300px;
        }
        .small_box #two{
            width: 200px;
            height: 300px;
            background-color: rgb(44, 173, 224);
            text-align: center;
            line-height: 300px;
        }
        .small_box #three{
            width: 200px;
            height: 300px;
            background-color: rgb(127, 51, 197);
            text-align: center;
            line-height: 300px;
        }
    </style>
<body>
    <div class="big_box">
    <ul>
        <li><a href="#one">小猫</a></li>
        <li><a href="#two">小狗</a></li>
        <li><a href="#three">小鸡</a></li>
    </ul>
        <div class="small_box">
            <div id="one">喵喵喵喵喵</div>
            <div id="two">汪汪汪汪汪</div>
            <div id="three">咕咕咕咕咕</div>
        </div> 
    </div>
</body>

运行结果如下:

点击左侧小猫,会弹出第一个盒子。
在这里插入图片描述
点击左侧小狗,会弹出第二个盒子。
在这里插入图片描述
点击左侧小鸡,会弹出第三个盒子。
在这里插入图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值