首页 > 开发 > CSS > 正文

利用CSS伪元素创建带三角形的提示框的实现方法

2024-07-11 08:36:30
字体:
来源:转载
供稿:网友

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.bottombottom .arrow {    
    top: -11px;    
    left: 50%;    
    margin-left: -11px;    
    border-top-width: 0;    
    border-bottom-color: #7d7d7d;    
}    
.tooltip-wrapper.bottombottom .arrow:after {    
    top: 1px;    
    margin-left: -10px;    
    border-top-width: 0;    
    border-bottom-color: white;    

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表