鼠标经过按钮上方 ,hover的时候,侧边栏向右滑出显示,且可点击(hover显示侧导航)

1. html代码示例:

结构要点: 要显示的**侧边栏是按钮的子级 **

  <div class="btn_slidebar">
    显示侧边栏
      <ul  class="test_slidebar">
        <li>分类1</li>
        <li>分类2</li>
        <li>分类3</li>
      </ul>
    </div>
2. css代码示例:
.btn_slidebar{ 
  width:100px;
  height: 40px;
  background: rgb(78, 194, 233);
  line-height: 40px;
  color:#fff;
  border-radius: 8px;
  box-shadow: 4px 2px 4px #808e8f;
  cursor: pointer;
}

.test_slidebar{
  width:150px;
  background: lightcoral;
  margin-top:20px;
  margin-left:-200px; /* 1. 初始,让侧边栏在屏幕外部 */
  transition: margin-left 0.5s; /* 2. 让margin-left有一个过渡效果,看实际情况,如果用了定位,也可以控制定位的left 值 */
}

.btn_slidebar:hover .test_slidebar{ /* */
  margin-left:0px; /* 3.  鼠标经过按钮的时候,让侧边栏回到原来的位置*/
}

鼠标移入后效果:
在这里插入图片描述

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 HTMLCSS 和 JavaScript 来实现这个功能。以下是一个简单的实现示例: 1. HTML 代码 ```html <!DOCTYPE html> <html> <head> <title>侧边栏示例</title> <style> .sidebar { height: 100%; width: 0; position: fixed; top: 0; left: 0; background-color: #111; overflow-x: hidden; padding-top: 60px; transition: 0.5s; } .sidebar a { padding: 8px 8px 8px 32px; text-decoration: none; font-size: 25px; color: #818181; display: block; transition: 0.3s; } .sidebar a:hover { color: #f1f1f1; } .sidebar .closebtn { position: absolute; top: 0; right: 25px; font-size: 36px; margin-left: 50px; } .openbtn { font-size: 20px; cursor: pointer; background-color: #111; color: white; padding: 10px 15px; border: none; } .openbtn:hover { background-color: #444; } </style> </head> <body> <div id="mySidebar" class="sidebar"> <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a> <a href="#">链接 1</a> <a href="#">链接 2</a> <a href="#">链接 3</a> </div> <button class="openbtn" onclick="openNav()">☰ 打开侧边栏</button> <script> function openNav() { document.getElementById("mySidebar").style.width = "250px"; } function closeNav() { document.getElementById("mySidebar").style.width = "0"; } </script> </body> </html> ``` 2. CSS 代码 这里使用了一个名为 `sidebar` 的类来定义侧边栏的样式,包括它的高度、宽度、位置、背景颜色、内边距等。 3. JavaScript 代码 用来控制侧边栏的打开和关闭。 通过点击 `openbtn` 按钮,调用 `openNav()` 函数打开侧边栏,关闭按钮通过 `closeNav()` 函数来实现。 希望这个示例对你有所帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值