用html做一个母亲节向日葵花
时间: 2023-12-22 11:04:11 浏览: 45
好的,我可以帮你实现这个小项目。以下是一个简单的 HTML 代码,可以绘制一个向日葵花的形状:
```html
<!DOCTYPE html>
<html>
<head>
<title>母亲节向日葵花</title>
<style type="text/css">
.sunflower {
border-radius: 50%;
width: 200px;
height: 200px;
background-color: yellow;
position: relative;
overflow: hidden;
}
.petals {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
transform: rotate(0deg);
transform-origin: center center;
}
.petal {
position: absolute;
background-color: #FFC107;
border-radius: 50px 50px 0 0;
width: 50px;
height: 100px;
top: 10px;
left: 75px;
animation: petal 4s ease-in-out infinite;
}
.petal:nth-child(1) {
transform: rotate(25deg);
}
.petal:nth-child(2) {
transform: rotate(50deg);
}
.petal:nth-child(3) {
transform: rotate(75deg);
}
.petal:nth-child(4) {
transform: rotate(100deg);
}
.petal:nth-child(5) {
transform: rotate(125deg);
}
.petal:nth-child(6) {
transform: rotate(150deg);
}
.petal:nth-child(7) {
transform: rotate(175deg);
}
.petal:nth-child(8) {
transform: rotate(200deg);
}
.petal:nth-child(9) {
transform: rotate(225deg);
}
.petal:nth-child(10) {
transform: rotate(250deg);
}
.petal:nth-child(11) {
transform: rotate(275deg);
}
.petal:nth-child(12) {
transform: rotate(300deg);
}
.petal:nth-child(13) {
transform: rotate(325deg);
}
.petal:nth-child(14) {
transform: rotate(350deg);
}
.stalk {
position: absolute;
top: 200px;
left: 90px;
background-color: green;
width: 20px;
height: 100px;
border-radius: 10px;
}
.flower-center {
position: absolute;
top: 80px;
left: 80px;
background-color: black;
width: 40px;
height: 40px;
border-radius: 50%;
}
@keyframes petal {
0% {
transform: rotate(0deg);
}
50% {
transform: rotate(15deg);
}
100% {
transform: rotate(0deg);
}
}
</style>
</head>
<body>
<div class="sunflower">
<div class="petals">
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
<div class="petal"></div>
</div>
<div class="stalk"></div>
<div class="flower-center"></div>
</div>
</body>
</html>
```
在这个代码中,我们使用了 CSS 的 `border-radius` 属性来定义向日葵花的圆形轮廓。然后,我们使用了绝对定位来放置花瓣、花梗和花心。花瓣的样式由 `.petal` 类定义,使用了 `transform` 属性来实现旋转动画,让花瓣随着时间轻微地抖动。通过 `.petal:nth-child(n)` 选择器,我们可以为每一个花瓣定义不同的旋转角度,最终形成一个完整的向日葵花形状。
你可以将这段代码复制到一个 HTML 文件中并在浏览器中打开,就能够看到一个简单的母亲节向日葵花了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)