# 提示气泡

常规方式

<style scoped>
main {
  width: 100%;
  padding: 99px 69px;
  display: flex;
  flex-wrap: wrap;
}
.poptip {
  position: relative;
  z-index: 101;
}
/*更改定位及 translate 即可修改气泡位置*/
.poptip::before, .poptip::after {
  visibility: hidden;
  opacity: 0;
  transform: translate3d(0, 0, 0);
  transition: all 0.3s ease 0.2s;
  box-sizing: border-box;
}

.poptip::before {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 8px 0 8px;
  border-color: #30363d transparent transparent transparent;
  left: calc(50% - 8px);
  top: 0px;
  transform: translateX(0%) translateY(-12px);
}

.poptip::after {
  font-size: 14px;
  color: #fff;
  content: attr(aria-controls);
  position: absolute;
  padding: 6px 12px;
  white-space: nowrap;
  z-index: -1;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%) translateY(-12px);
  background: #30363d;
  line-height: 1;
  border-radius: 2px;
}

.poptip:hover::before, .poptip:hover::after {
  visibility: visible;
  opacity: 1;
}

.btn {
  min-width: 100px;
  line-height: 1.5;
  padding: 5px 10px;
  color: #fff;
  background: #00adb5;
  border-radius: 4px;
  text-align: center;
  cursor: pointer;
}
</style>
<template>
  <main>
    <div class="poptip btn" aria-controls="弹出气泡">poptip</div>
  </main>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
poptip

dark主题

<style scoped>
  main {
    width: 100%;
    padding: 99px 69px;
    display: flex;
    flex-wrap: wrap;
  }
  .cell {
    width: calc(33.33333% - 8px); height: 52px;
    text-align: center;
    line-height: 52px;
    border-radius: 8px;
    background: #F7F5F1;
    cursor: pointer;
    position: relative;
    border-color: #b4a078;
  }
  .cell.empty {
    background: transparent;
    cursor: default;
    pointer-events: none;
  }
  .cell:not(:nth-of-type(3n)) {
    margin-right: 12px;
    margin-bottom: 12px;
  }
  .cell:hover {
    color: #b4a078;
    font-weight: 900;
  }
  .cell[class*=poptip--]::before,
  .cell[class*=poptip--]::after {
    visibility: hidden;
    opacity: 0;
    transform: translate3d(0,0,0);
    transition: all .3s ease .05s;
  }
  .cell[class*=poptip--]:hover::before,
  .cell[class*=poptip--]:hover::after {
    visibility: visible;
    opacity: 1;
  }
  .cell[class*=poptip--]::before {
    content: '';
    position: absolute;
    width: 0; height: 0;
    border: 6px solid transparent;
  }
  .cell[class*=poptip--]::after {
    content: attr(aria-controls);
    position: absolute;
    background: #b4a078;
    font-size: 12px;
    font-weight: normal;
    color: white;
    line-height: 12px;
    padding: 6px 12px;
    white-space: nowrap;
    border-radius: 2px;
    box-shadow: 0px 0px 3px #b4a078;
  }
  .cell[class*=poptip--top]::before {
    border-top-color: inherit;
  }
  .cell[class*=poptip--right]::before {
    border-right-color: inherit;
  }
  .cell[class*=poptip--bottom]::before {
    border-bottom-color: inherit;
  }
  .cell[class*=poptip--left]::before {
    border-left-color: inherit;
  }
  /*top && bottom*/
  .cell[class*=poptip--top]::before,
  .cell[class*=poptip--bottom]::before {
    left: calc(50% - 6px);
  }
  .cell[class*=poptip--top]::after,
  .cell[class*=poptip--bottom]::after {
    left: 50%;
    transform: translateX(-50%);
  }
  .cell[class*=poptip--top]::before {
    top: 0px;
  }
  .cell[class*=poptip--top]:hover::before {
    transform: translateX(0%) translateY(-10px);
  }
  .cell[class*=poptip--top]::after {
    bottom: 100%;
    margin-bottom: -1px;
  }
  .cell[class*=poptip--top]:hover::after {
    transform: translateX(-50%) translateY(-10px);
  }
  .cell[class*=poptip--bottom]::before {
    bottom: 0;
  }
  .cell[class*=poptip--bottom]:hover::before {
    transform: translateX(0%) translateY(10px);
  }
  .cell[class*=poptip--bottom]::after {
    top: 100%;
    margin-top: -1px;
  }
  .cell[class*=poptip--bottom]:hover::after {
    transform: translateX(-50%) translateY(10px);
  }
  /*left && right*/
  .cell[class*=poptip--right]::before,
  .cell[class*=poptip--left]::before {
    top: calc(50% - 6px);
  }
  .cell[class*=poptip--right]::after,
  .cell[class*=poptip--left]::after {
    top: 50%;
    transform: translateY(-50%);
  }
  .cell[class*=poptip--right]::before {
    right: 0;
  }
  .cell[class*=poptip--right]:hover::before {
    transform: translateX(10px) translateY(0%);
  }
  .cell[class*=poptip--right]::after {
    left: 100%;
    margin-left: -1px;
  }
  .cell[class*=poptip--right]:hover::after {
    transform: translateX(10px) translateY(-50%);;
  }
  .cell[class*=poptip--left]::before {
    left: 0;
  }
  .cell[class*=poptip--left]:hover::before {
    transform: translateX(-10px) translateY(0%);
  }
  .cell[class*=poptip--left]::after {
    right: 100%;
    margin-right: -1px;
  }
  .cell[class*=poptip--left]:hover::after {
    transform: translateX(-10px) translateY(-50%);;
  }
</style>
<template>
  <main>
    <div class="cell poptip--top-left" aria-controls="top-left">top-left</div>
    <div class="cell poptip--top" aria-controls="top">top</div>
    <div class="cell poptip--top-right" aria-controls="top-right">top-right</div>
    <div class="cell poptip--left" aria-controls="left">left</div>
    <div class="cell empty"></div>
    <div class="cell poptip--right" aria-controls="right">right</div>
    <div class="cell poptip--bottom-left" aria-controls="bottom-left">bottom-left</div>
    <div class="cell poptip--bottom" aria-controls="bottom">bottom</div>
    <div class="cell poptip--bottom-right" aria-controls="bottom-right">bottom-right</div>
  </main>
</template>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
top-left
top
top-right
left
right
bottom-left
bottom
bottom-right

light主题:filter: drop-shadow()

top-left
top
top-right
left
right
bottom-left
bottom
bottom-right
上次更新: 2023-10-28