css制作玫瑰
使用CSS绘制玫瑰
通过CSS的伪元素、变形和渐变可以创建简单的玫瑰图案。以下是一种实现方法:
<div class="rose"></div>
.rose {
position: relative;
width: 100px;
height: 100px;
margin: 50px auto;
}
.rose::before, .rose::after {
content: "";
position: absolute;
border-radius: 50%;
}
.rose::before {
width: 80px;
height: 80px;
background: radial-gradient(circle, #ff3366 30%, transparent 30%),
radial-gradient(circle, #ff3366 40%, transparent 40%),
radial-gradient(circle, #ff3366 50%, transparent 50%);
transform: rotate(45deg);
top: 10px;
left: 10px;
}
.rose::after {
width: 40px;
height: 80px;
background: #339933;
transform: rotate(-15deg);
bottom: -40px;
left: 30px;
}
使用CSS动画增强效果
添加花瓣飘动动画效果:
@keyframes petal {
0% { transform: rotate(45deg) scale(1); }
50% { transform: rotate(50deg) scale(1.05); }
100% { transform: rotate(45deg) scale(1); }
}
.rose::before {
animation: petal 3s ease-in-out infinite;
}
创建多层花瓣结构
更复杂的玫瑰需要多层div结构:
<div class="rose">
<div class="petal p1"></div>
<div class="petal p2"></div>
<div class="petal p3"></div>
<div class="stem"></div>
</div>
.petal {
position: absolute;
border-radius: 50%;
background: radial-gradient(circle, #ff6699 0%, #ff3366 100%);
}
.p1 { width: 80px; height: 80px; transform: rotate(45deg); }
.p2 { width: 70px; height: 70px; transform: rotate(90deg); top: 5px; }
.p3 { width: 60px; height: 60px; transform: rotate(135deg); top: 10px; }
.stem {
position: absolute;
width: 8px;
height: 120px;
background: linear-gradient(to bottom, #339933, #226622);
top: 80px;
left: 46px;
}
使用CSS变量控制颜色
通过CSS变量方便调整颜色:

:root {
--petal-color: #ff3366;
--stem-color: #339933;
}
.petal {
background: radial-gradient(circle,
color-mix(in srgb, var(--petal-color), white 20%),
var(--petal-color));
}
这些方法展示了如何使用纯CSS创建玫瑰图案,通过组合基本形状、渐变和变换实现复杂效果。实际应用中可以根据需要调整花瓣层数、大小和颜色渐变。






