CSS实现3D菜单效果

Posted 知其黑、受其白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSS实现3D菜单效果相关的知识,希望对你有一定的参考价值。

阅读目录

效果

index.html

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>CSS实现3D菜单效果</title>
	<!-- https://fontawesome.dashgame.com/ 字体图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" />
	<link rel="stylesheet" href="index.css">
  </head>
  <body>
    <ul>
      <li style="--i:8;--clr:#00a6bc;">
		  <a href="">
			  <span>
				  <i class="fa fa-caret-right"></i>
			  </span> 网站首页</a>
	  </li>
      <li style="--i:7;--clr:#0a66c2;"><a href=""><span><i class="fa fa-caret-right"></i></span>HTML/CSS </a></li>
      <li style="--i:6;--clr:#1da1f2;"><a href=""><span><i class="fa fa-caret-right"></i></span>javascript</a></li>
      <li style="--i:5;--clr:#c32aa3;"><a href=""><span><i class="fa fa-caret-right"></i></span> 源码案例</a></li>
      <li style="--i:4;--clr:#d4620b;"><a href=""><span><i class="fa fa-caret-right"></i></span> 电子书</a></li>
      <li style="--i:3;--clr:#0a66c2;"><a href=""><span><i class="fa fa-caret-right"></i></span> 在线课程</a></li>
      <li style="--i:2;--clr:#d30aa8;"><a href=""><span><i class="fa fa-caret-right"></i></span> 建站主机</a></li>
      <li style="--i:1;--clr:#00a6bc;"><a href=""><span><i class="fa fa-caret-right"></i></span> 开发工具</a></li>
    </ul>
  </body>
</html>

index.css

*

  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Oswald', sans-serif;

body 

  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #434750;
  gap: 130px;

ul 

  position: relative;
  transform: skewY(-15deg);

ul li 

  position: relative;
  list-style: none;
  width: 120px;
  padding: 15px;
  background: #3e3f46;
  z-index: calc(1 * var(--i));
  transition: 0.5s;

ul li:hover 

  background: var(--clr);
  transform: translateX(-50px);

ul li::before 

  content: '';
  position: absolute;
  top: 0;
  left: -40px;
  width: 40px;
  height: 100%;
  background: #3e3f46;
  filter: brightness(0.7);
  transform-origin: right;
  transform: skewY(45deg);
  transition: 0.5s;

ul li:hover::before 

  background: var(--clr);
  filter: brightness(0.7);

ul li::after 

  content: '';
  position: absolute;
  top: -40px;
  left: 0px;
  width: 100%;
  height: 40px;
  background: #3e3f46;
  filter: brightness(0.9);
  transform-origin: bottom;
  transform: skewX(45deg);
  transition: 0.5s;

ul li:hover::after 

  background: var(--clr);
  filter: brightness(0.9);

ul li a 

  text-decoration: none;
  color: #999;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: 0.5s;

ul li:hover a

  color: #fff;

ul li:last-child::after 

  box-shadow: -120px 120px 20px rgba(0,0,0,0.25);

ul li a span 

  position: absolute;
  top: 0;
  left: -40px;
  width: 40px;
  text-align: center;
  height: 100%;
  transform-origin: right;
  transform: skewY(45deg);
  transition: 0.5s;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.25em;
  opacity: 0.5;

ul li:hover a span 

  opacity: 1;

以上是关于CSS实现3D菜单效果的主要内容,如果未能解决你的问题,请参考以下文章

jQuery鼠标悬停3d菜单展开动画

CSS3 iPhone样式的3D菜单

使用纯CSS代码实现3D旋转效果

开发小技巧023—如何使用HTML和CSS实现3D文字效果

使用JS与CSS3的翻转实现3D翻牌效果

CSS transform-style属性实现3D效果