会话框的样式怎么做php,如何使用CSS制作对话框气泡

我们在和别人通过微信或者qq聊天的时候都会有对话框气泡,那么这个对话框气泡是怎么实现的呢?本篇文章来给大家介绍一下如何使用CSS制作我们经常可以看到的对话框气泡,下面我们来看具体的内容。

首先我们来看一下我们需要制作的对话框的效果

0326e79d441cfd54310696511cf679db.png

接下来我们就来看看这几种对话气泡的实现方法

我们来看一下如何实现箭头向左的对话气泡

我们需要先来制作一个框架

8e4a7a67696be67265239f77fdf7922a.png

代码如下

HTML代码

左边

CSS代码.balloon-left {

position: relative;

display: inline-block;

padding: 0 15px;

width: auto;

min-width: 150px;

height: 40px;

line-height: 34px;

text-align: center;

background: #44FF44;

border: 3px solid #000000;

z-index: 0;

}

接着,我们使用:before来制作箭头部分,用:after来制作箭头的边

CSS代码.balloon-left:before {

border-style: solid;

border-width: 10px 10px 10px 0;

border-color: transparent #44FF44 transparent transparent;

content: "";

position: absolute;

top: 50%; left: -8px;

margin-top: -9px;

display: block;

width: 0px;

height: 0px;

z-index: 0;

}

.balloon-left:after {

border-style: solid;

border-width: 11px 11px 11px 0;

border-color: transparent #000000 transparent transparent;

content: "";

position: absolute;

top: 50%; left: -12px;

margin-top: -10px;

display: block;

width: 0px;

height: 0px;

z-index: -1;

}

运行效果入下所示

f251f9b0ee4c753d461ccaae72ddc9c4.png

这样就完成了第一个对话气泡

下面我们就来根据上述方法来制作箭头向右的对话气泡

代码如下

HTML代码

右边

CSS代码.balloon-right {

position: relative;

display: inline-block;

padding: 0 15px;

width: auto;

min-width: 150px;

height: 40px;

line-height: 34px;

text-align: center;

background: #44FF44;

border: 3px solid #000000;

z-index: 0;

}

.balloon-right:before {

border-style: solid;

border-width: 10px 0 10px 10px;

border-color: transparent transparent transparent #44FF44;

content: "";

position: absolute;

top: 50%; right: -8px;

margin-top: -9px;

display: block;

width: 0px;

height: 0px;

z-index: 0;

}

.balloon-right:after {

border-style: solid;

border-width: 11px 0 11px 11px;

border-color: transparent transparent transparent #000000;

content: "";

position: absolute;

top: 50%; right: -12px;

margin-top: -10px;

display: block;

width: 0px;

height: 0px;

z-index: -1;

}

运行上述代码的效果如下所示:是一个向右的气泡

c53dc9210cb4f9e6a45f3007e33e03f0.png

最后我们来说箭头向左和向右的对话气泡

我们需要用到border-radius属性让气泡变得圆滑

代码如下

HTML代码

向上
向下

CSS代码.balloon-top {

position: relative;

display: inline-block;

padding: 0 15px;

width: auto;

min-width: 150px;

height: 40px;

line-height: 32px;

text-align: center;

background: #44FF44;

border: 3px solid #000000;

z-index: 0;

border-radius: 60%;

}

.balloon-top:before {

border-style: solid;

border-width: 0 10px 10px 10px;

border-color: transparent transparent #44FF44 transparent;

content: "";

position: absolute;

top: -8px; left: 50%;

margin-left: -9px;

display: block;

width: 0px;

height: 0px;

z-index: 0;

}

.balloon-top:after {

border-style: solid;

border-width: 0 11px 11px 11px;

border-color: transparent transparent #000000 transparent;

content: "";

position: absolute;

top: -12px; left: 50%;

margin-left: -10px;

display: block;

width: 0px;

height: 0px;

z-index: -1;

}

.balloon-bottom {

position: relative;

display: inline-block;

padding: 0 15px;

width: auto;

min-width: 150px;

height: 40px;

line-height: 34px;

text-align: center;

background-color: #44FF44;

border: 3px solid #000000;

z-index: 0;

border-radius: 60%;

}

.balloon-bottom:before {

content: "";

position: absolute;

bottom: -8px; left: 50%;

margin-left: -9px;

width: 0px;

height: 0px;

border-style: solid;

border-width: 10px 10px 0 10px;

border-color: #44FF44 transparent transparent transparent;

z-index: 0;

}

.balloon-bottom:after {

border-style: solid;

border-width: 11px 11px 0 11px;

border-color: #000000 transparent transparent transparent;

content: "";

position: absolute;

bottom: -12px; left: 50%;

margin-left: -10px;

width: 0px;

height: 0px;

z-index: -1;

}

效果如下所示

2ce2e1432ba331396a599e470eaf4b86.png

总结

CSS部分有点复杂,但你可以根据以上示例通过自定义颜色和形状来制作各种类型的对话框气泡。

本篇文章到这里就全部结束了,更多精彩内容大家可以移步到php中文网的CSS视频教程栏目进一步的学习!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值