純CSS實現小三角提示資訊

來源:互聯網
上載者:User

標籤:css3   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]


純CSS實現小三角提示資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.