写个圣诞树,送给女朋友,使用前端html,css,JavaScript写
时间: 2023-02-06 20:37:41 浏览: 69
好的,这是一个使用 HTML、CSS 和 JavaScript 写的圣诞树的示例:
HTML:
```
<div id="christmas-tree">
<div class="star"></div>
<div class="trunk"></div>
<div class="tree-section">
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
</div>
<div class="gifts">
<div class="gift"></div>
<div class="gift"></div>
<div class="gift"></div>
<div class="gift"></div>
</div>
</div>
```
CSS:
```
#christmas-tree {
position: relative;
width: 400px;
height: 600px;
margin: 0 auto;
}
.star {
position: absolute;
top: -30px;
left: 50%;
transform: translateX(-50%);
width: 60px;
height: 60px;
border-radius: 50%;
background: gold;
box-shadow: 0 0 20px gold;
}
.trunk {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 40px;
height: 80px;
background: brown;
}
.tree-section {
position: absolute;
top: 50px;
left: 50%;
transform: translateX(-50%);
width: 200px;
height: 400px;
}
.tree-layer {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 50%;
background: green;
box-shadow: 0 0 20px green;
transform: translateY(-50%);
}
.tree-layer:nth-child(1) {
width: 200px;
height: 200px;
}
.tree-layer:nth-child(2) {
width: 180px;
height: 180px;
top: 20px;
}
.tree-layer:nth-child(3) {
width: 160px;
height: 160px;
top: 40px;
}
.tree-layer:nth-child(4) {
width: 140px;
height: 140px;
top: 60px;
}
.tree-layer:nth-child(5) {
width: 120px;
height: 120px;
top: 80px;
}
.gifts {
position: absolute;
bottom: 60px;
left: 50%;
transform: translateX(-50%);
display: flex;
}
.gift {
width: 50px;
height: 50px;
background
阅读全文