<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS气泡形状</title> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f5f5f5; } .bubble { background-color: #ffeb3b; padding: 10px 20px; border-radius: 20px; display: inline-block; max-width: 80%; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } .container { display: flex; flex-direction: column; gap: 20px; width: 100%; max-width: 500px; } </style> </head> <body> <div class="container"> <div class="bubble">这是一条短消息</div> <div class="bubble">这是一条较长的消息,可以看到气泡会自动根据内容调整宽度</div> <div class="bubble">这是一条非常非常长的消息,当内容超过一定宽度时,气泡会自动换行,保持良好的视觉效果和阅读体验</div> </div> </body> </html><!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS气泡形状 - 精确版</title> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; background-color: #f5f5f5; font-family: Arial, sans-serif; } .bubble { background-color: #ffeb3b; padding: 8px 15px; display: inline-block; position: relative; border-radius: 6px; margin: 10px; } .bubble::before { content: ""; position: absolute; left: 0; bottom: 0; width: 15px; height: 15px; background-color: #ffeb3b; border-bottom-left-radius: 15px; clip-path: polygon(0 0, 100% 100%, 0 100%); transform: translateX(-8px); } .container { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; width: 100%; max-width: 500px; } </style> </head> <body> <div class="container"> <div class="bubble">1</div> <div class="bubble">这是一条短消息</div> <div class="bubble">这是一条较长的消息示例</div> <div class="bubble">这是一条非常长的消息,可以看到气泡会自动调整大小</div> </div> </body> </html>