css制作咖啡
使用CSS制作咖啡图案
通过CSS的border-radius、box-shadow和渐变等属性,可以绘制一个简化的咖啡杯图案。以下是实现代码:
<div class="coffee-cup"></div>
.coffee-cup {
width: 100px;
height: 80px;
background: linear-gradient(to right, #6F4E37, #4B3621);
border-radius: 0 0 40px 40px;
position: relative;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
.coffee-cup::before {
content: "";
position: absolute;
top: -15px;
left: 20px;
width: 60px;
height: 20px;
background: #D8C7B5;
border-radius: 50%;
}
添加咖啡热气动画
通过伪元素和CSS动画模拟热气效果:
.coffee-cup::after {
content: "";
position: absolute;
top: -40px;
left: 45px;
width: 10px;
height: 30px;
background: rgba(255, 255, 255, 0.6);
border-radius: 5px;
animation: steam 2s infinite ease-out;
}
@keyframes steam {
0% { transform: translateY(0) scale(1); opacity: 0.6; }
100% { transform: translateY(-20px) scale(1.5); opacity: 0; }
}
制作咖啡液面细节
增加液面光泽效果增强真实感:

.coffee-cup::before {
/* 原有代码基础上添加 */
box-shadow:
inset 0 5px 5px rgba(255, 255, 255, 0.2),
inset 0 -5px 5px rgba(0, 0, 0, 0.3);
}
完整示例代码
<!DOCTYPE html>
<html>
<head>
<style>
.coffee-cup {
width: 100px;
height: 80px;
background: linear-gradient(to right, #6F4E37, #4B3621);
border-radius: 0 0 40px 40px;
position: relative;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
margin: 50px;
}
.coffee-cup::before {
content: "";
position: absolute;
top: -15px;
left: 20px;
width: 60px;
height: 20px;
background: #D8C7B5;
border-radius: 50%;
box-shadow:
inset 0 5px 5px rgba(255, 255, 255, 0.2),
inset 0 -5px 5px rgba(0, 0, 0, 0.3);
}
.coffee-cup::after {
content: "";
position: absolute;
top: -40px;
left: 45px;
width: 10px;
height: 30px;
background: rgba(255, 255, 255, 0.6);
border-radius: 5px;
animation: steam 2s infinite ease-out;
}
@keyframes steam {
0% { transform: translateY(0) scale(1); opacity: 0.6; }
100% { transform: translateY(-20px) scale(1.5); opacity: 0; }
}
</style>
</head>
<body>
<div class="coffee-cup"></div>
</body>
</html>
通过调整颜色、尺寸和动画参数,可以创建不同风格的咖啡视觉效果。这种纯CSS实现方式适合网页装饰元素或加载动画场景。






