HTML5 CSS3 专题 :诱人的实例 3D展示商品信息
以下是一个简单的HTML和CSS代码示例,展示如何使用HTML5和CSS3创建一个3D呈现的商品信息卡片:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>3D Product Card</title>
<style>
.product-card {
width: 200px;
height: 260px;
background-color: #fff;
border: 1px solid #ddd;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
perspective: 1000px;
}
.product-card .face {
position: relative;
width: 100%;
height: 100%;
backface-visibility: hidden;
transition: transform 0.6s;
}
.product-card .face.back {
transform: rotateY(180deg);
background-color: #f8f8f8;
display: flex;
justify-content: center;
align-items: center;
font-size: 20px;
color: #333;
}
.product-card .face.front {
background-color: #f0f0f0;
display: flex;
flex-direction: column;
justify-content: space-between;
cursor: pointer;
}
.product-card .face.front img {
width: 100%;
height: 150px;
object-fit: cover;
}
.product-card .face.front .info {
padding: 10px;
}
.product-card:hover .face {
transform: rotateY(180deg);
}
</style>
</head>
<body>
<div class="product-card">
<div class="face front">
<img src="product-image.jpg" alt="Product Image">
<div class="info">
<p>Product Name</p>
<p>$99.99</p>
</div>
</div>
<div class="face back">
Description of the product goes here.
</div>
</div>
</body>
</html>
这个示例使用了CSS3的perspective
和transform
属性来创建3D效果,并使用:hover
伪类来触发卡片翻转的动画。这个简单的3D卡片可以作为学习如何制作类似效果的起点。
评论已关闭