怎么使用纯CSS代码实现带有金属光泽的立体按钮的动画效果(css,web开发)

时间:2024-05-08 11:28:03 作者 : 石家庄SEO 分类 : web开发
  • TAG :

  代码解读

  在dom中定义一个容器:

  <divclass="box">BUTTON</div>

  容器居中显示:

  html,body{

  height:100%;

  display:flex;

  align-items:center;

  justify-content:center;

  background-color:skyblue;

  }

  设置按钮的2d样式,为了便于调整按钮尺寸,使用了变量:

  .box{

  background:linear-gradient(toright,gold,darkorange);

  color:white;

  --width:250px;

  --height:calc(var(--width)/3);

  width:var(--width);

  height:var(--height);

  text-align:center;

  line-height:var(--height);

  font-size:calc(var(--height)/2.5);

  font-family:sans-serif;

  letter-spacing:0.2em;

  border:1pxsoliddarkgoldenrod;

  border-radius:2em;

  }

  设置按钮的3d样式:

  .box{

  transform:perspective(500px)rotateY(-15deg);

  text-shadow:6px3px2pxrgba(0,0,0,0.2);

  box-shadow:2px005pxrgba(0,0,0,0.2);

  }

  定义按钮的鼠标划过动画效果:

  .box:hover{

  transform:perspective(500px)rotateY(15deg);

  text-shadow:-6px3px2pxrgba(0,0,0,0.2);

  box-shadow:-2px005pxrgba(0,0,0,0.2);

  }

  .box{

  transition:0.5s;

  }

  用伪元素增加光泽:

  .box{

  position:relative;

  }

  .box::before{

  content:'';

  position:absolute;

  width:100%;

  height:100%;

  background:linear-gradient(toright,transparent,white,transparent);

  left:0;

  }

  定义光泽动画效果:

  .box::before{

  left:-100%;

  transition:0.5s;

  }

  .box:hover::before{

  left:100%;

  }

  最后,隐藏容器之外的内容:

  .box{

  overflow:hidden;

  }

  大功告成!

怎么使用纯CSS代码实现带有金属光泽的立体按钮的动画效果

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:怎么使用纯CSS代码实现带有金属光泽的立体按钮的动画效果的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:怎么使用纯CSS实现彩虹条纹文字的效果下一篇:

5 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18