css制作气球
使用CSS制作气球效果
通过CSS的伪元素、边框属性和阴影效果可以轻松实现气球或气泡的视觉效果。以下是两种常见的气球样式实现方法:

基础圆形气球

.balloon {
width: 100px;
height: 100px;
background-color: #ff6b6b;
border-radius: 50%;
position: relative;
box-shadow: inset -5px -5px 10px rgba(0,0,0,0.2);
}
.balloon::after {
content: "";
position: absolute;
bottom: -10px;
left: 50%;
width: 20px;
height: 20px;
background-color: inherit;
transform: translateX(-50%) rotate(45deg);
}
对话气泡样式
.bubble {
position: relative;
width: 200px;
padding: 15px;
background: #88b7d5;
border-radius: 10px;
color: white;
}
.bubble::after {
content: "";
position: absolute;
bottom: -10px;
left: 20%;
border-width: 15px 10px 0;
border-style: solid;
border-color: #88b7d5 transparent;
}
添加动画效果
通过CSS动画让气球具有漂浮感:
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-20px); }
}
.balloon {
animation: float 3s ease-in-out infinite;
}
进阶样式技巧
- 渐变颜色:使用
background: linear-gradient()创建更生动的颜色过渡 - 高光效果:添加白色椭圆伪元素模拟反光
- 阴影层次:多层
box-shadow增强立体感 - 响应式尺寸:使用
vw/vh单位实现自适应大小
完整示例可通过CodePen等平台查看实时效果,搜索关键词"CSS balloon codepen"可找到多种实现方案。






