六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 132|回复: 0

分享Css3设计---纯Css实现超酷的iphone玻璃气泡效果

[复制链接]

升级  88%

12

主题

12

主题

12

主题

童生

Rank: 1

积分
44
 楼主| 发表于 2013-2-7 22:18:01 | 显示全部楼层 |阅读模式

demo地址:http://xueduany.github.com/KitJs/KitJs/index.html#bubble
号外:kitjs官方讨论扣扣群建立了,扣扣群号88093625,欢迎大家加入,讨论前端相关话题
最近做手机项目时候,需要实现一个类似iphone SMS效果的气泡效果。
这里分享下实现心得,
 
首先分析下iphone的气泡效果有一下特点
1. 圆角
2. 向下的外阴影
3. 上边和下边的内阴影
4. 上边内的一个内嵌的玻璃气泡的反光效果
 
首先定义一个容器,盒模型为display: inline-block,方便自适应文字大小
.bubble {
    position: relative;
    display: inline-block;
    min-width: 30px;
    max-width: 200px;
    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);
}
设置断词,避免文字过长,撑开容器,同时设置最小宽度,最大宽度
设置圆角,border-radius
设置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 .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
}
 
在气泡内嵌一个显示内容的block,使用block的before伪元素,实现一个圆角的渐变气泡
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% );
最后,通过气泡的before和after伪元素,实现三角
.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;
}
 
最终效果图:
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表