使用CSS-skew()函数实现3D侧边栏

1. 通过2Dskew()扭曲函数实现真实3D抽屉效果,可作为侧边栏使用。

7769498b88ef4c159f42a8de4895ecfc.gif

效果图

2. CSS代码

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}
body ul {
  transform: skewY(-15deg);
}
body ul li {
  position: relative;
  list-style: none;
  background-color: #3e4046;
  z-index: var(--i);
  transition: 0.6s;
}
body ul li a {
  display: block;
  width: 200px;
  height: 60px;
  text-align: center;
  line-height: 60px;
  color: #fff;
  text-decoration: none;
}
body ul li::before {
  position: absolute;
  left: -60px;
  content: "";
  width: 60px;
  height: 60px;
  background-color: #2f3133;
  transform-origin: right;
  transform: skewY(45deg);
}
body ul li::after {
  position: absolute;
  top: -60px;
  content: "";
  width: 200px;
  height: 60px;
  background-color: #36383e;
  transform-origin: bottom;
  transform: skewX(45deg);
}
body ul li:hover {
  background-color: #33a3ef;
  transform: translateX(-50px);
}

 3. HTML代码

<body>
  <ul>
    <li style="--i:4"><a href="">A</a></li>
    <li style="--i:3"><a href="">B</a></li>
    <li style="--i:2"><a href="">C</a></li>
    <li style="--i:1"><a href="">D</a></li>
  </ul>
</body>

4. 注意:

        1.skewX()以逆时针为正向扭曲,例如:skew(45deg)是向左倾斜。

        2.skewY()以顺时针为正向扭曲,例如:skew(-15deg)是向上扭曲。

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Shar豪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值