H5静态代码开发圣诞树
时间: 2023-11-13 10:23:26 浏览: 139
html5作的圣诞树
好的,以下是一个简单的H5静态代码开发圣诞树的示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>圣诞树</title>
<style type="text/css">
body {
background-color: #2C3E50;
text-align: center;
color: #FFFFFF;
}
.tree {
margin: auto;
margin-top: 100px;
width: 200px;
height: 300px;
background-color: #FFFFFF;
border-radius: 0 0 10px 10px;
position: relative;
overflow: hidden;
}
.tree:before {
content: "";
position: absolute;
top: 0;
left: 50%;
width: 0;
height: 0;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
border-bottom: 150px solid green;
transform: translateX(-50%);
}
.tree:after {
content: "";
position: absolute;
top: 70px;
left: 50%;
width: 0;
height: 0;
border-left: 80px solid transparent;
border-right: 80px solid transparent;
border-top: 100px solid green;
transform: translateX(-50%);
}
.star {
position: absolute;
top: 20px;
left: 50%;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 30px solid yellow;
transform: translateX(-50%) rotateZ(35deg);
}
.balls {
position: absolute;
top: 150px;
left: 50%;
transform: translateX(-50%);
}
.balls span {
display: inline-block;
margin-right: 10px;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: red;
animation: move 2s ease-in-out infinite;
}
.balls span:nth-child(2) {
animation-delay: 0.2s;
}
.balls span:nth-child(3) {
animation-delay: 0.4s;
}
.balls span:nth-child(4) {
animation-delay: 0.6s;
}
.balls span:nth-child(5) {
animation-delay: 0.8s;
}
@keyframes move {
0% {
transform: translateY(0);
}
50% {
transform: translateY(20px);
}
100% {
transform: translateY(0);
}
}
</style>
</head>
<body>
<div class="tree">
<div class="star"></div>
<div class="balls">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
</body>
</html>
```
你可以将上述代码复制到本地的html文件中,用浏览器打开即可看到一个简单的圣诞树效果。其中,使用伪元素:before和:after实现树的形状,使用绝对定位的.star元素实现星星的形状,使用相对定位的.balls元素和动画实现彩球的滚动效果。
阅读全文