工具提示箭头
如需创建在工具提示的指定侧面显示的箭头,请在工具提示后添加“空的”内容,并使用伪元素类 ::after 和 content 属性。箭头本身是使用边框创建的。这会使工具提示看起来像气泡。
本例演示如何在工具提示的底部添加箭头:
底部箭头
.tooltip .tooltiptext::after {
content: " ";
position: absolute;
top: 100%; /* At the bottom of the tooltip */
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: black transparent transparent transparent;
}
结果:
请把鼠标指针移动到这段文字上方
Tooltip text
例子解释
将箭头定位在工具提示内:top: 100% 将箭头放置在工具提示的底部。left: 50% 将使箭头居中。
注意:border-width 属性指定箭头的大小。如果您更改此设置,也请将 margin-left 值更改为相同值。这将使箭头居中。
border-color 用于将内容转换为箭头。我们将上边框设置为黑色,其余设置为透明。如果所有面都是黑色,则最终将得到一个黑色的方形框。
本例演示了如何在工具提示的顶部添加箭头。请注意,这次我们设置了下边框的颜色:
顶部箭头
.tooltip .tooltiptext::after {
content: " ";
position: absolute;
bottom: 100%; /* At the top of the tooltip */
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent black transparent;
}
结果:
请把鼠标指针移动到这段文字上方
Tooltip text
本例演示如何在工具提示的左侧添加箭头:
左侧箭头
.tooltip .tooltiptext::after {
content: " ";
position: absolute;
top: 50%;
right: 100%; /* To the left of the tooltip */
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent black transparent transparent;
}
结果:
请把鼠标指针移动到这段文字上方
Tooltip text
本例演示如何在工具提示的右侧添加箭头:
右侧箭头
.tooltip .tooltiptext::after {
content: " ";
position: absolute;
top: 50%;
left: 100%; /* To the right of the tooltip */
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent transparent black;
}
结果:
请把鼠标指针移动到这段文字上方
Tooltip text