纯css实现电梯导航

该代码示例展示了如何利用HTML的`<a>`标签href属性创建锚点,结合CSS的Grid布局和Sticky定位来创建一个简单的电梯导航。页面主要内容分为三部分:服饰、家电和生鲜,侧边栏的导航链接可以固定在屏幕中,方便用户快速跳转至相应区块。
摘要由CSDN通过智能技术生成

 结构

 <body>
    <div class="container">
      <div class="goods">
        <div class="box1" id="box1">服饰</div>
        <div class="box2" id="box2">家电</div>
        <div class="box3" id="box3">生鲜</div>
      </div>

      <div class="slidebar">
        <a href="#box1">服饰</a>
        <a href="#box2">家电</a>
        <a href="#box3">生鲜</a>
      </div>
    </div>
  </body>

css

 <style>
      .container {
        width: 100%;
        height: 3000px;
        display: grid;
        grid-template-rows: 1fr;
        grid-template-columns: 1fr 150px;
        grid-row: 1 / span 6;
        grid-column: 2 / span 3;
      }

      .container .goods {
        display: grid;
        grid-row-gap: 600px;
      }

      .container .goods div {
        background-color: green;
      }
      .container .goods div:nth-child(2) {
        background-color: red;
      }

      .container .slidebar {
        position: sticky;
        left: 0;
        top: 500px;
        margin: auto;
      }

      .container .slidebar a {
        text-decoration: none;
        display: block;
        width: 100px;
        height: 100px;
        background-color: pink;
        line-height: 100px;
        text-align: center;
      }

      .container .slidebar a:nth-child(2) {
        background-color: yellowgreen;
      }
    </style>

使用a链接的href锚点,使用grid栅格布局,使用sticky电梯导航的粘性布局

实现简单的电梯导航

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值