用HTML生成一个完整的圣诞树代码
时间: 2024-05-11 17:17:11 浏览: 108
好的,以下是一个用 HTML 生成完整的圣诞树的代码:
```
<!DOCTYPE html>
<html>
<head>
<title>圣诞树</title>
<style>
body {
background-color: #F0F8FF;
text-align: center;
}
.tree {
display: inline-block;
margin-top: 50px;
position: relative;
}
.tree:before {
content: "";
position: absolute;
top: 0;
left: 50%;
margin-left: -50px;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid green;
}
.tree:after {
content: "";
position: absolute;
top: 50px;
left: 50%;
margin-left: -75px;
width: 0;
height: 0;
border-left: 75px solid transparent;
border-right: 75px solid transparent;
border-bottom: 150px solid green;
}
.star {
display: inline-block;
position: absolute;
top: -20px;
left: 50%;
margin-left: -20px;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-bottom: 40px solid gold;
transform: rotate(45deg);
}
.light {
display: inline-block;
position: absolute;
border-radius: 50%;
background-color: #FFFACD;
}
.light1 {
top: 80px;
left: 20%;
width: 20px;
height: 20px;
}
.light2 {
top: 120px;
left: 30%;
width: 30px;
height: 30px;
}
.light3 {
top: 100px;
left: 50%;
width: 40px;
height: 40px;
}
.light4 {
top: 130px;
left: 70%;
width: 30px;
height: 30px;
}
.light5 {
top: 90px;
right: 20%;
width: 20px;
height: 20px;
}
</style>
</head>
<body>
<div class="tree">
<div class="star"></div>
</div>
<div class="light light1"></div>
<div class="light light2"></div>
<div class="light light3"></div>
<div class="light light4"></div>
<div class="light light5"></div>
</body>
</html>
```
这个代码会生成一个绿色的圣诞树,树顶有一个金色的星星,树上有五颗白色的圆形灯饰。
阅读全文