css蛋形怎么制作
使用CSS制作蛋形
蛋形可以通过CSS的border-radius属性结合椭圆或自定义形状实现。以下是几种常见方法:
基础椭圆法
通过设置border-radius为50%生成椭圆,调整宽度和高度比例模拟蛋形:

.egg {
width: 100px;
height: 130px;
background: #ffcc00;
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}
- 上方半径略大于下方,形成上宽下窄的效果。
自定义边界半径
精细控制四个角的水平和垂直半径:

.egg {
width: 120px;
height: 160px;
background: #ff9966;
border-radius: 50% 50% 50% 50% / 80% 80% 20% 20%;
}
使用伪元素增强立体感
通过阴影或伪元素增加立体效果:
.egg {
position: relative;
width: 100px;
height: 140px;
background: linear-gradient(to bottom, #ffcc00, #ff9900);
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}
.egg::after {
content: '';
position: absolute;
top: 10%;
left: 20%;
width: 20px;
height: 10px;
background: rgba(255,255,255,0.5);
border-radius: 50%;
}
SVG替代方案
如需更复杂的蛋形,可嵌入SVG:
<svg width="120" height="160" viewBox="0 0 120 160">
<path d="M60,10 C100,10 110,80 60,150 C10,80 20,10 60,10 Z" fill="#ffcc00"/>
</svg>
关键注意事项
- 调整
border-radius的百分比值可改变蛋形的顶部和底部曲线。 - 高度通常大于宽度以符合蛋的比例。
- 渐变或高光效果可增强视觉真实感。






