html手写动态圣诞树
时间: 2023-12-18 19:04:23 浏览: 81
用HTML实现一个动态的圣诞树
以下是一个使用HTML和CSS手写的动态圣诞树的例子,它使用了CSS3动画和伪元素来实现动态效果:
```html
<!DOCTYPE html>
<html>
<head>
<title>动态圣诞树</title>
<style>
body {
background-color: #1a1a1a;
}
.tree {
position: relative;
margin: 0 auto;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid #00ff00;
animation: sway 2s ease-in-out infinite;
}
.tree:before {
content: "";
position: absolute;
top: -50px;
left: -50px;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid #00ff00;
transform: rotate(60deg);
}
.tree:after {
content: "";
position: absolute;
top: -50px;
left: 50px;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid #00ff00;
transform: rotate(-60deg);
}
@keyframes sway {
0% {
transform: rotateZ(0deg);
}
50% {
transform: rotateZ(3deg);
}
100% {
transform: rotateZ(0deg);
}
}
.star {
position: absolute;
top: -30px;
left: 50%;
margin-left: -15px;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 30px solid #ffff00;
transform: rotateZ(-35deg);
animation: twinkle 1s ease-in-out infinite;
}
.star:before {
content: "";
position: absolute;
top: 10px;
left: -20px;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 30px solid #ffff00;
transform: rotateZ(70deg);
}
.star:after {
content: "";
position: absolute;
top: 10px;
right: -20px;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 30px solid #ffff00;
transform: rotateZ(-70deg);
}
@keyframes twinkle {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
</style>
</head>
<body>
<div class="tree"></div>
<div class="star"></div>
</body>
</html>
```
阅读全文