使用HTML和CSS的明信片动画效果

84 篇文章 0 订阅

使用HTML和CSS的明信片动画效果

教程地址原文地址(YouTube)

B站教程原文转载(bilibili)

两个视频的内容相同,第二个为转载

效果图

在这里插入图片描述

代码区

html

<div class="wrapper">
  <div class="mail">
    <div class="cover"></div>
    <div class="letter"><h1>@</h1></div>
  </div>
</div>

CSS

*{
  margin: 0;
  padding: 0;
}

body {
  background: #302929;
}

.wrapper{
  position: absolute; /* 绝对定位 */
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);  /* 移动x,y */
}

.mail{
  width: 300px;
  height: 200px;
  background: #ff8789;
  position: relative;
  transform-style: preserve-3d; /* 保留3Dx效果 */
  border-bottom-left-radius: 20px; /* 左下圆角 */
  border-bottom-right-radius: 20px;
  cursor: pointer; /* 鼠标样式 */
}
 /* 右边 */
.mail:before{ /* 之前添加 */
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  border-left: 140px solid Transparent;
  border-right: 150px solid #ff393c;
  border-top: 100px solid Transparent;
  border-bottom: 100px solid #ff393c;
  z-index: 5; /* 层叠排序 */
  border-bottom-right-radius: 10px;
}
 /* 左边 */
.mail:after{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  border-left: 150px solid #ff5355;
  border-right: 140px solid Transparent;
  border-top: 100px solid Transparent;
  border-bottom: 100px solid #ff5355;
  z-index: 4;
  border-bottom-left-radius: 10px;
}

.cover:before{ /* 上边 */
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  border-left: 150px solid transparent;
  border-right: 150px solid transparent;
  border-top: 100px solid #ff8789;
  border-bottom: 100px solid transparent;
  z-index: 6;
  transform-origin: top;
  transform: rotateX(0deg);
  transition: all 1s 1s ease;
}

.letter{ /* 卡片 */
  position: absolute;
  z-index: 3;
  top: 0px;
  left: 10px;
  background: #dedede;
  width: 280px;
  height: 180px;
  border-radius: 20px;
  transition: all 1s ease; /* 过渡时间 */
}

.letter h1{ /* @符号 */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  font-size: 80px;
  color: #798992;
  font-weight: 900;
}

.mail:hover .cover:before{
  transform: rotateX(180deg); /* 翻转X轴 */
  transition: all 1s ease;
}

.mail:hover .letter{
  top: -80px; /* 利用top进行移动 */
  transition: all 1s 1s ease;
}


JS


教程地址原文地址(YouTube)

B站教程原文转载(bilibili)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值