使用 CSS3 实现 tip 提示

这里是使用了CSS的after和before两个伪元素实现的tip小提示。伪元素的特性就是:允许我们添加额外元素而不扰乱文档本身。事实上,伪元素表现上就像是《真正》的元素,我们能够给它们添加任何样式,比如改变它们的颜色、添加背景色、调整字体大小、调整它们中的文本等等。

HTML:

百度一下

CSS:

 .css-tip {
    position: relative;
    z-index: 99;
}
 .css-tip:hover:after, .css-tip:hover:before {
    opacity: 1;
}
.css-tip:before {
    content: "";
    border: 4px transparent solid;
    border-top-color: #428bca;
    position: absolute;
    bottom: 22px;
    left: 50%;
    opacity: 0;
    -webkit-transition: opacity .5s ease-in-out;
    -moz-transition: opacity .5s ease-in-out;
    -ms-transition: opacity .5s ease-in-out;
    -o-transition: opacity .5s ease-in-out;
    transition: opacity .5s ease-in-out;
}

.css-tip:after {
    border: 1px solid #428bca;
    background-color: #C1E8F9;
    border-radius: 3px;
    bottom: 30px;
    color: #428bca;
    content: attr(data-tip);
    font-size: 12px;
    line-height: 1.3;
    padding: 5px;
    position: absolute;
    text-align: center;
    width: 100px;
    margin-left: -85px;
    opacity: 0;
    -webkit-transition: opacity .5s ease-in-out;
    -moz-transition: opacity .5s ease-in-out;
    -ms-transition: opacity .5s ease-in-out;
    -o-transition: opacity .5s ease-in-out;
    transition: opacity .5s ease-in-out;
}

 

 

除特别注明外,本站所有文章均为原创,转载请注明原文链接:https://www.myblogbo.com/article/20.html

 Top