效果例图:
1、首先是html代码:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="./3.css">
<title>Document</title>
</head>
<body>
<div class ="card">
<div class="front">
<h2>正面</h2>
</div>
<div class="back">
<h2>背面</h2>
</div>
</div>
</body>
</html>
2、css3 关键代码:
.card{
position: relative;
width: 300px;
height: 200px;
}
.card:hover .front{
transform: rotateY(-180deg);
}
.card:hover .back{
transform: rotateY(0);
}
.front,.back{
position: absolute;
width: 100%;
height: 100%;
color: #fff;
border-radius: 10px;
backface-visibility: hidden;
transition: all 1s ease;
display: flex;
justify-content: center;
align-items: center;
}
.front{
background-color: brown;
}
.back{
background-color: darkcyan;
transform: rotateY(180deg);
}