添加一個小符號,可做鏈接引導或是一個簡單的提示
通過CSS的Tooltip提示框,我們可以在頁面中一些需要進行內容補充的地方添加一個符號,訪客將鼠標移動到該符號或是點擊該符號,即可查看相關補充內容。這一次的CSS筆記向大家介紹下相關內容。
- 技術支持:菜鳥教程
方案一:鏈接法
這種提示框用CSS很好展示,給一個問好加上園圈就好了,例如這樣:
<a target="_blank" href="http://www.kartiktrivedi.com/#"style="display: inline-block;
width: 18px;
height: 18px;
line-height: 18px;
background: hsla(0,0%,100%,.1);
text-align: center;
color: #111;
font-family: REEJI-BigYoung-BoldGB;
font-size: 14px;
border: 1px solid;
border-radius: 100%; ">?</a>
效果展示:
?方案二:文本提示
當然,如果只是一些簡單的提醒,專門做個頁面進行介紹就不太適合了,可以試試這個,當鼠標移到到圖標上,就有文本提示:
<span class="tooltip"><span class="tooltip-icon">?</span><span class="tip-content">
<span class="tip-content-inner">
Tooltip提示框
</span>
</span>
</span>
<style type="text/css">
.tooltip{
position: relative;
display: inline-block;
margin-left: 5px;
margin-right: 5px;
height: 16px;
line-height: 16px;
vertical-align: middle;
}
.tooltip-icon{
display: block;
width: 14px;
height: 14px;
line-height: 14px;
border: 1px solid #999;
border-radius: 50%;
font-size: 12px;
font-weight: 700;
font-family: "caption", Arial;
text-align: center;
}
.tip-content{
z-index: 999999;
display: none;
position: absolute;
left: -5px;
bottom: 30px;
width: 240px;
}
.tip-content-inner{
position: absolute;
bottom: 0;
left: 0;
display: block;
width: auto;
max-width: 200px;
padding: 10px;
line-height: 20px;
border: 1px solid #ccc;
background: #fff;
line-height: 20px;
color: #333;
font-size: 16px;
}
.tip-content-inner:before{
content: "";
position: absolute;
left: 7px;
bottom: -24px;
border-style: solid solid solid solid;
border-color: #ccc transparent transparent transparent;
border-width: 12px 6px;
}
.tip-content-inner:after{
content: "";
position: absolute;
left: 8px;
bottom: -20px;
border-style: solid solid solid solid;
border-color: #fff transparent transparent transparent;
border-width: 10px 5px;
}
.tooltip:hover > .tip-content{
display: block;
}
</style>
效果展示:
Tooltip提示框代碼來源: