网页制作-3D旋转卡片
两种旋转卡片的制作
旋转卡片(1)
代码
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D旋转卡片</title>
<link rel="stylesheet" href="./3dcard.css">
</head>
<body>
<div class="card_3d">
<div class="front">
<p>缘分让我们遇到</p>
</div>
<div class="back">
<p>求点赞</p>
<p>求点赞</p>
<p>求点赞</p>
<p>求点赞</p>
</div>
</div>
</body>
</html>
css代码
*{
margin: 0;
padding: 0;
}
body{
/* 弹性布局 水平加垂直 */
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-image: linear-gradient(200deg,#5ee7df,#b490ca);
/* 增加旋转立体感 */
perspective: 1000px;
}
.card_3d{
position: relative;
width: 300px;
height: 450px;
border-radius: 30px;
cursor: pointer;
background-color: #fff;
box-shadow: 1px 1px 20px rgba(0,0,0,0.1);
/* 给父元素添加一个3d盒子,等到子元素到背面,这个元素使添加到父元素的,当影响的是子元素 */
transform-style: preserve-3d;
/* 添加默认动画 */
animation: rotate-reverse 1.2s cubic-bezier(0.66,-0.47,0.33,1.5) forwards;
}
/* 设置鼠标移入动画执行 */
.card_3d:hover{
/* 动画(名称 时长 第三个属性是贝塞尔曲线 forward使动画到100%后会停下来) */
animation: rotate 1.2s cubic-bezier(0.66,-0.47,0.33,1.5) forwards;
}
.card_3d .front, .card_3d .back{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
/* 平均分配子元素 */
justify-content: space-around;
font-size: 20px;
background-color: #fff;
border-radius: 30px;
backface-visibility: hidden;
}
.card_3d .back{
/* 此页要到背面去 所以沿y轴旋转 */
transform: rotateY(180deg);
}
/* 动画 */
@keyframes rotate{
0%{
transform: rotateY(0deg);
}
100%{
transform: rotateY(180deg);
}
}
@keyframes rotate-reverser{
0%{
transform: rotateY(180deg);
}
100%{
transform: rotateY(0deg);
}
}
效果图
鼠标悬浮,卡片翻转
旋转卡片(2)
代码
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D旋转卡片(2)</title>
<link rel="stylesheet" href="./3dcard2.css">
</head>
<body>
<div class="fzcard">
<div id="s_img">
<img src="./img/1.jpg" id="a1">
<img src="./img/2.jpg" id="a2">
</div>
</div>
</body>
</html>
css代码
*{
margin: 0;
padding: 0;
}
body{
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
background-color: aqua;
}
.fzcard{
width: 400px;
height: 600px;
perspective: 1000px;
}
#s_img{
width: 400px;
height: 600px;
position: relative;
/* 创建3d空间 */
transform-style: preserve-3d;
}
#s_img img{
width: 100%;
height: 100%;
position: absolute;
border-radius: 30px;
box-shadow: 0 0 15px rgb(0, 0, 0);
backface-visibility: hidden;
transition: 2s;
}
#a2{
transform: rotateY(180deg);
}
.fzcard:hover #a2{
transform: rotateY(0deg);
}
.fzcard:hover #a1{
transform: rotateY(-180deg);
}
所需图片
效果图
鼠标悬浮卡片翻转
标签:卡片,100%,transform,height,rotateY,html,3D,3d From: https://blog.csdn.net/qq_62652856/article/details/136995535