文章目录
  1. 1. 示列代码

bootstrap中已经有现成的气泡可用,而且还有一些高级功能封装,以下是用css3和html自己画聊天气泡的原理,实际上就是使用after,before还有圆角的实现的。

示列代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!doctype html> 
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="content-type" />
<link rel="stylesheet" href="bubble.css" />

<link rel="stylesheet" href="css.css" />
</head>
<body>
<div id="wraper1">
<div style="height:20px;" ></div>
<div style="text-align: left;padding-left:20px">
<div class="bubble">
<div class="content">
ABC
</div>
</div>
</div>
</div>
<div id="wraper2">
<div style="text-align: right;padding-right:20px;">
<div class="bubble">
<div class="content">AAAA
</div>
</div>
</div>
</div>
<div id="wraper3">
<div style="text-align: left;padding-left:20px">
<div class="bubble">
<div class="content">
FFF
</div>
</div>
</div>
</div>
<div id="wraper4">
<div style="text-align: right;padding-right:20px;">
<div class="bubble">
<div class="content"> OOO
</div>
</div>
</div>
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#wraper1,
#wraper2,
#wraper3,
#wraper4 {
color: #000;
position: relative;
width: 100%;
background: #dbe2ed;
}

.bubble {
position: relative;
display: inline-block;
min-width: 30px;
max-width: 300px;
word-break: break-all;
word-wrap: break-word;
min-height: 22px;
background: #d2d2d2;
border-radius: 15px;
margin-bottom: 20px;
padding: 6px 8px;
-webkit-box-shadow: 0px 1px 2px #000, inset 0px 4px 4px rgba(0,0,0,.3), inset 0px -4px 4px rgba(255,255,255,.5);
-moz-shadow: 0px 1px 2px #000, inset 0px 4px 4px rgba(0,0,0,.3), inset 0px -4px 4px rgba(255,255,255,.5);
box-shadow: 0px 1px 2px #000, inset 0px 4px 4px rgba(0,0,0,.3), inset 0px -4px 4px rgba(255,255,255,.5);
}

.bubble:before {
content: '';
display: block;
font-size: 0;
width: 0;
height: 0;
border-width: 6px;
position: absolute;
bottom: -12px;
left: 12px;
border-color: #4a4c50 transparent transparent #4a4c50;
border-style: solid dashed dashed solid;
}

.bubble:after {
content: '';
display: block;
font-size: 0;
position: absolute;
bottom: -9px;
left: 13px;
width: 0;
height: 0;
border-width: 5px;
border-color: #e8e8e8 transparent transparent #e8e8e8;
border-style: solid dashed dashed solid;
}

.bubble .content {
position: relative;
padding: 0 4px;
}

.bubble .content:before {
content: '';
position: absolute;
margin: auto;
top: -5px;
left: 0;
width: 100%;
height: 12px;
background-image: -webkit-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(255,255,255,0.2) 90%, rgba(255,255,255,0) 90% );
background-image: -moz-linear-gradient(top, rgba(255,255,255,1) 0%, rgba(255,255,255,0.2) 90%, rgba(255,255,255,0) 90% );
border-radius: 10px
}




/**
* 绿色气泡
*/

#wraper2 .bubble {
background: #b7da2b;
}

#wraper2 .bubble:before {
left: auto;
right: 12px;
border-color: #4a4c50 #4a4c50 transparent transparent;
border-style: solid solid dashed dashed;
}

#wraper2 .bubble:after {
left: auto;
right: 13px;
border-color: #daec93 #daec93 transparent transparent;
border-style: solid solid dashed dashed;
}



/**
* 橙色气泡
*/

#wraper3 .bubble {
background: #f6d031;
}

#wraper3 .bubble:after {
border-color: #fae796 transparent transparent #fae796;
border-style: solid dashed dashed solid;
}



/**
* 黄色气泡
*/

#wraper4 .bubble {
background: #feed24;
}

#wraper4 .bubble:before {
left: auto;
right: 12px;
border-color: #4a4c50 #4a4c50 transparent transparent;
border-style: solid solid dashed dashed;
}

#wraper4 .bubble:after {
left: auto;
right: 13px;
border-color: #fef690 #fef690 transparent transparent;
border-style: solid solid dashed dashed;
}

以上代码摘自:http://blog.csdn.net/xuweilinjijis/article/details/8695585

此文是本站原创,转载请标注作者和链接出处!