纯CSS实现小三角提示信息

实现后的效果如下:

不带边框的

带边框的

在此提供两种实现方式:

1、不带边框的

css:

*{margin:0;padding:0;}
        body{
            background:#666;
            font:14px/20px "Microsoft YaHei";
            text-align: left;
        }
        .entry{
            position: relative;
            margin-left: 20px;
            margin-top:20px;
            width:200px;
            background:#fff;
            padding:10px;
            /*设置圆角*/
            -webkit-border-radius:5px;
            -moz-border-radius:5px;
            border-radius:5px;
        }
        /*左三角*/
        .entry-trangle-left{
            position:absolute;
            bottom:15px;
            left:-10px;
            width:0;
            height:0;
            border-top:15px solid transparent;
            border-bottom:15px solid transparent;
            border-right:15px solid #fff;
        }
        /*右三角*/
        .entry-trangle-right{
            position:absolute;
            top:15px;
            right:-10px;
            width:0;
            height:0;
            border-top:15px solid transparent;
            border-bottom:15px solid transparent;
            border-left:15px solid #fff;
        }
        /*上三角*/
        .entry-trangle-top{
            position:absolute;
            top:-10px;
            left:20px;
            width:0;
            height:0;
            border-left:15px solid transparent;
            border-right:15px solid transparent;
            border-bottom:15px solid #fff;
        }
        /*下三角*/
        .entry-trangle-bottom{
            position:absolute;
            bottom:-10px;
            left:20px;
            width:0;
            height:0;
            border-left:15px solid transparent;
            border-right:15px solid transparent;
            border-top:15px solid #fff;
        }

html:

<div class="entry">
    <div class="entry-trangle-left"><!--本Div只来实现三角形,无其他作用--></div>
    hello,我出生了<br/>
    hello,我出生了
</div>
<div class="entry">
    <div class="entry-trangle-right"><!--本Div只来实现三角形,无其他作用--></div>
    hello,我出生了<br/>
    hello,我出生了
</div>
<div class="entry">
    <div class="entry-trangle-top"><!--本Div只来实现三角形,无其他作用--></div>
    hello,我出生了<br/>
    hello,我出生了
</div>
<div class="entry">
    <div class="entry-trangle-bottom"><!--本Div只来实现三角形,无其他作用--></div>
    hello,我出生了<br/>
    hello,我出生了
</div>

2、带边框的

css:

 /*上三角*/
        .tag-top{
             margin: 20px;
             padding: 5px;
             width:300px;
             height:60px;
             border:2px solid #f99;
             position:relative;
             background-color:#FFF;
             /*设置圆角*/
             -webkit-border-radius:5px;
             -moz-border-radius:5px;
             border-radius:5px;
         }
        .tag-top:before,.tag-top:after{
            content:"";
            display:block;
            border-width:15px;
            position:absolute;
            top:-30px;
            left:100px;
            border-style:solid dashed dashed solid;
            border-color:transparent  transparent #f99 transparent;
            font-size:0;
            line-height:0;
        }
        .tag-top:after{
            top:-27px;
            border-color: transparent transparent #FFF transparent;
        }
        /*下三角*/
        .tag-bottom{
            margin: 20px;
            padding: 5px;
            width:300px;
            height:60px;
            border:2px solid #f99;
            position:relative;
            background-color:#FFF;
            /*设置圆角*/
            -webkit-border-radius:5px;
            -moz-border-radius:5px;
            border-radius:5px;
        }
        .tag-bottom:before,.tag-bottom:after{
            content:"";
            display:block;
            border-width:15px;
            position:absolute;
            bottom:-30px;
            left:100px;
            border-style:solid dashed dashed solid;
            border-color:#f99 transparent  transparent transparent;
            font-size:0;
            line-height:0;
        }
        .tag-bottom:after{
            bottom:-27px;
            border-color: #FFF transparent transparent transparent;
        }
        /*左三角*/
        .tag-left{
            margin: 20px;
            padding: 5px;
            width:300px;
            height:60px;
            border:2px solid #f99;
            position:relative;
            background-color:#FFF;
            /*设置圆角*/
            -webkit-border-radius:5px;
            -moz-border-radius:5px;
            border-radius:5px;
        }
        .tag-left:before,.tag-left:after{
            content:"";
            display:block;
            border-width:15px;
            position:absolute;
            left:-30px;
            top:20px;
            border-style:dashed solid solid dashed;
            border-color:transparent #f99 transparent  transparent;
            font-size:0;
            line-height:0;
        }
        .tag-left:after{
            left:-27px;
            border-color:transparent #FFF transparent transparent ;
        }
        .tag-right{
            margin: 20px;
            padding: 5px;
            width:300px;
            height:60px;
            border:2px solid #f99;
            position:relative;
            background-color:#FFF;
            /*设置圆角*/
            -webkit-border-radius:5px;
            -moz-border-radius:5px;
            border-radius:5px;
        }
        .tag-right:before,.tag-right:after{
            content:"";
            display:block;
            border-width:15px;
            position:absolute;
            right:-30px;
            top:20px;
            border-style:dashed solid solid dashed;
            border-color:transparent transparent transparent #f99;
            font-size:0;
            line-height:0;
        }
        .tag-right:after{
            right:-27px;
            border-color:transparent transparent  transparent #FFF ;
        }

html:

<div class="tag-top">
    css3气泡框
</div>
<div class="tag-bottom">
    css3气泡框
</div>
<div class="tag-left">
    css3气泡框
</div>
<div class="tag-right">
    css3气泡框
</div>

此外,如若,设置边框的颜色与背景色相同,也能得到没有边框的:

css:

 .tag-right-noborder{
            margin: 20px;
            padding: 5px;
            width:300px;
            height:60px;
            border:2px solid #FFF;
            position:relative;
            background-color:#FFF;
            /*设置圆角*/
            -webkit-border-radius:5px;
            -moz-border-radius:5px;
            border-radius:5px;
        }
        .tag-right-noborder:before,.tag-right-noborder:after{
            content:"";
            display:block;
            border-width:15px;
            position:absolute;
            right:-30px;
            top:20px;
            border-style:dashed solid solid dashed;
            border-color:transparent transparent transparent #FFF;
            font-size:0;
            line-height:0;
        }
        .tag-right-noborder:after{
            right:-27px;
            border-color:transparent transparent  transparent #FFF ;
        }

html:

<div class="tag-right-noborder">
    css3气泡框
</div>

实现后的效果:

如有疑问,可联系:

QQ:1004740957

Email:[email protected]

时间: 2024-08-13 15:20:24

纯CSS实现小三角提示信息的相关文章

纯CSS制作小三角

<div class="triangle-up"></div> <--向上的三角--> <div class="triangle-down"></div> <div class="triangle-left"></div> <div class="triangle-right"></div> 123测试

纯CSS制作的三角箭头

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>纯CSS制作的三角箭头丨kiddy<

css制作小三角

视觉稿中经常有些小三角,如下图.每次用图片做太不方便了,我们看看用css实现的效果(支持ie6,7哦) <style> /*border实现三角*/ /*箭头向上*/ .arrow-top{ width : 0; height : 0; font-size : 0; line-height : 0; border-left: 5px dashed transparent; border-right: 5px dashed transparent; border-bottom: 5px soli

用CSS制作小三角提示符号

今天在项目中遇到了如下图的切图要求. 对,重点就是那个小三角提示符号. html 结构如下 1 <div class="wrap"> 2 <div class="up-arr1"></div> 3 <div class="up-arr2"></div> 4 </div> css 结构如下: .wrap { position: relative; } .up-arr1 { po

纯CSS实现小圆点和三角形图案

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>纯CSS制作三角形和小圆点</title> <style> .arrowbox{width:40px;height:30px;background: #000;paddin

css的小三角实现的方式

1. width:0 height:0 border宽度,颜色和透明实现. 有例子. http://www.igooda.cn/jzjl/20140401472.html 2. 还有一种利用图片.(效率没有纯css写的高,但是简单,推荐) 3. 利用一个小的文字图标. 这里边还有一个经典的absolute套absolute的例子. 4. 利用padding之类的.可以的话做一个梯形看看. ========================================= <style type=

纯CSS 实现tooltip 内容提示信息效果

Tooltip 也就是内容的提示信息,合理使用可以给用户比较好的体验. 实现方法有很多种,有很多JS 插件,我这里介绍的是纯CSS实现的方法,兼容性也比较靠谱,IE8+均可正常显示.实现方法也非常简单. html结构 <a class="css-tooltip" href="http://fatesinger.com/73887" data-tooltip="137 likes with 3.43k reads">WordPress

纯css制作带三角(兼容所有浏览器)

如何用 border 来制作三角. html 代码如下: 代码如下: <div class="arrow-up"></div> <div class="arrow-down"></div> <div class="arrow-left"></div> <div class="arrow-right"></div> css 代码如下:

(转载) css实现小三角(尖角)

在各种网站里面,我们会经常看到类似于这样的尖角:(示例:新浪微博) 它实现的方式有多种,哪种才是最简单的?哪种才是最优秀的?首先我声明一下,我还不清楚这个东西具体叫什么名字(哪位知道还望告知),暂且叫尖角吧,通俗易懂.我查看了各大互联网公司的网站,包括腾讯.百度.新浪.天猫.去哪网, 腾讯: 百度: 去哪网: 天猫: 其中,百度和腾讯直接用的背景图片,简单粗暴,没有艺术细菌. 优点:形状随意: 缺点:不方便维护: 下面要说的是新浪微博,右键小尖角,查看元素,可以看到一段代码: <div clas