CSS伪元素非常有用,它提供了一种无需多余的DOM元素来实现一些常见的功能的方法,以下利用其实现一个带三角形的tooltip。

下面是DOM结构:
下面是对应的CSS样式:

XML/HTML Code复制内容到剪贴板 <div class="tooltip-wrapper bottom">         <div class="arrow"></div>         <div class="content">             This is content         </div>     </div>   

CSS Code 复制内容到剪贴板 .tooltip-wrapper {          position absolute ;          z-index : 9999;          padding 5px ;          background white ;          border 1px   solid   #7d7d7d ;          border -radius:  5px ;     }     .tooltip-wrapper .arrow,     .tooltip-wrapper .arrow:after {          position absolute ;          display block ;          width : 0;          height : 0;          border-color transparent ;          border-style solid ;     }     .tooltip-wrapper .arrow {          border-width 11px ;     }     .tooltip-wrapper .arrow:after {          content "" ;          border-width 10px ;     }     .tooltip-wrapper. bottom bottom  .arrow {          top : - 11px ;          left : 50%;          margin-left : - 11px ;          border-top - width : 0;          border-bottom - color #7d7d7d ;     }     .tooltip-wrapper. bottom bottom  .arrow:after {          top 1px ;          margin-left : - 10px ;          border-top - width : 0;          border-bottom - color white ;     }  

以上这篇利用CSS伪元素创建带三角形的提示框的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

原文地址:http://imgbuyun.weixiu-service.com/up79/202309/xrkaxtkduyf.html