最终效果图:
![](https://i-blog.csdnimg.cn/blog_migrate/bcb26edcd729f063c64eefef0087265a.jpeg)
基本原理
先设定一个背景色的普通div盒子,然后使用上篇post得到的三角型图标,把div盒子设置为相对定位模式,三角型图标设置为绝对定位,位置相对于div盒子,调整到合适的位置。这样就得到一个基本的tooltip,但是没有边框看起来总是不舒服,我们可以给div盒子设置一个边框,这没什么难度,但是三角形图标如何设置边框呢?这里我们通过一个取巧的方式,让两个不同颜色的三角形图标叠加,并且位置错开1px,这样底层三角形top border被遮盖,只露出左右border部分,叠加在一起我们就得到一个看似带边框的三角形图标。
step by step
1.先定义一个相对定位的盒子div:
1
2
|
<
div
class
=
"tooltips"
>
</
div
>
|
css:
1
2
3
4
5
6
7
8
|
.tooltips{
position
:
relative
;
width
:
300px
;
height
:
80px
;
line-height
:
60px
;
background
:
#D7E7FC
;
border-radius:
4px
;
}
|
效果:
2.接下来利用上篇post的知识我们给div盒子添加一个三角型图标:
1
2
3
|
<
div
class
=
"tooltips"
>
<
div
class
=
"arrow "
></
div
>
</
div
>
|
三角形图标css:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
.arrow{
position
:
absolute
;
color
:
#D7E7FC
;
width
:
0px
;
height
:
0px
;
line-height
:
0px
;
|