css制作静态气泡
使用CSS制作静态气泡效果
气泡效果常见于聊天界面或提示框,通过CSS的border-radius、box-shadow和伪元素实现。
基础气泡结构

<div class="bubble">Hello, this is a bubble!</div>
圆形气泡样式
.bubble {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: #4CAF50;
display: flex;
align-items: center;
justify-content: center;
color: white;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
对话框气泡样式

.bubble {
position: relative;
max-width: 200px;
padding: 12px;
background: #f1f1f1;
border-radius: 10px;
margin: 20px;
}
.bubble::after {
content: '';
position: absolute;
bottom: -10px;
left: 20px;
border-width: 10px 10px 0;
border-style: solid;
border-color: #f1f1f1 transparent;
}
添加阴影和渐变效果
.bubble {
background: linear-gradient(135deg, #6e8efb, #a777e3);
box-shadow: 0 3px 5px rgba(0,0,0,0.2);
color: white;
text-shadow: 0 1px 1px rgba(0,0,0,0.2);
}
多个气泡排列示例
.bubble-container {
display: flex;
flex-direction: column;
gap: 15px;
}
.bubble.left {
align-self: flex-start;
}
.bubble.right {
align-self: flex-end;
background: #0084ff;
}
.bubble.right::after {
left: auto;
right: 20px;
border-color: #0084ff transparent;
}
这些CSS代码片段可以组合使用,通过调整尺寸、颜色和定位创建各种静态气泡效果。






