当前位置:首页 > CSS

css制作蛋糕

2026-03-11 17:48:34CSS

CSS制作蛋糕的方法

使用CSS可以创建简单的蛋糕图形,主要通过div元素和CSS样式实现。以下是实现步骤:

HTML结构

<div class="cake">
  <div class="top"></div>
  <div class="middle"></div>
  <div class="bottom"></div>
  <div class="candle"></div>
  <div class="flame"></div>
</div>

CSS样式

.cake {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 50px auto;
}

.top {
  width: 180px;
  height: 40px;
  background: #f8c8dc;
  border-radius: 50% 50% 0 0;
  position: absolute;
  top: 0;
  left: 10px;
}

.middle {
  width: 200px;
  height: 60px;
  background: #f5a6c8;
  position: absolute;
  top: 40px;
  left: 0;
}

.bottom {
  width: 220px;
  height: 80px;
  background: #f082ac;
  position: absolute;
  top: 100px;
  left: -10px;
  border-radius: 0 0 20px 20px;
}

.candle {
  width: 10px;
  height: 40px;
  background: #fff;
  position: absolute;
  top: -40px;
  left: 95px;
}

.flame {
  width: 15px;
  height: 25px;
  background: #ffcc00;
  border-radius: 50% 50% 20% 20%;
  position: absolute;
  top: -65px;
  left: 92px;
  animation: flicker 0.5s infinite alternate;
}

@keyframes flicker {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.1); opacity: 0.8; }
}

添加装饰元素

蛋糕可以添加更多装饰元素,如糖霜或糖粒:

.decorations {
  position: absolute;
  width: 100%;
  height: 100%;
}

.decorations::before {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 50%;
  top: 20px;
  left: 30px;
}

.decorations::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border-radius: 50%;
  top: 20px;
  right: 30px;
}

动画效果

为蜡烛火焰添加动画效果,使其看起来更真实:

@keyframes flicker {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.7; }
}

响应式调整

通过媒体查询调整蛋糕大小,适应不同屏幕:

css制作蛋糕

@media (max-width: 600px) {
  .cake {
    transform: scale(0.7);
  }
}

以上代码组合可以创建一个简单的CSS蛋糕图形,包含三层蛋糕、蜡烛和火焰动画效果。通过调整颜色、尺寸和装饰元素,可以进一步定制蛋糕样式。

标签: 蛋糕css
分享给朋友:

相关文章

css制作导航栏

css制作导航栏

水平导航栏 使用 display: inline-block 或 flexbox 创建水平导航栏。设置背景色、内边距和悬停效果增强交互性。 <nav class="horizontal-nav…

css制作六边形

css制作六边形

使用CSS创建六边形的方法 通过CSS的clip-path属性可以轻松实现六边形效果。以下是一个基础示例: .hexagon { width: 100px; height: 55px;…

css简历制作

css简历制作

使用CSS制作简历的基本方法 选择简洁的布局结构,单列或双列布局适合大多数简历。使用display: flex或display: grid实现响应式设计,确保在不同设备上显示良好。 字体选择上,标题…

css制作流程图

css制作流程图

使用CSS制作流程图的方法 基础布局结构 采用HTML的<div>元素构建流程节点,结合CSS的flexbox或grid布局实现整体排列。节点间用伪元素或独立元素(如<span>…

css制作便签

css制作便签

CSS制作便签的方法 使用CSS可以轻松创建具有便签效果的样式,以下是一种常见的实现方式: HTML结构 <div class="note"> <h3>便签标题<…

css 制作箭头

css 制作箭头

使用 CSS 边框制作箭头 通过调整元素的边框宽度和颜色,利用透明边框的特性可以创建箭头效果。例如,制作一个向右的箭头: .arrow-right { width: 0; height: 0…