Hide title from tooltip

二次信任 提交于 2019-12-17 16:44:28

问题


I'm making a tooltip using CSS. Now using the following html code

<div title="This is some information for our tooltip." class="progress3">
</div>

and the following CSS

.progress3{
display: inline;
position: relative;
}

.progress3:hover:after{
background: #333;
background: rgba(0,0,0,.8);
border-radius: 5px;
bottom: 26px;
color: #fff;
content: attr(title);
left: 20%;
padding: 5px 15px;
position: absolute;
z-index: 98;
width: 220px;
content: attr(title);
}

.progress3:hover:before{
border: solid;
border-color: #333 transparent;
border-width: 6px 6px 0 6px;
bottom: 20px;
content: "";
left: 50%;
position: absolute;
z-index: 99;
}

Now it works, when I hover over it shows the tooltip, but it also shows the title... How do I remove what's circled in orange in the image below.


回答1:


Simply don't add the content via the title attribute, change it to something like data-tooltip.

.progress3:hover:after {
    content: attr(data-tooltip);
}

jsFiddle example

You could use JS/jQuery, but given the approach you are taking, it is impossible to hide/remove it while keeping functionality as you would then have nothing to add via CSS..

HTML

<div data-tooltip="This is some information for our tooltip." class="progress3">
</div>

CSS

.progress3 {
    position: relative;
    width: 100px;
    height: 100px;
    background: red;
}

.progress3:hover:after {
    background: #333;
    background: rgba(0,0,0,.8);
    border-radius: 5px;
    bottom: 26px;
    color: #fff;
    content: attr(data-tooltip);
    left: 20%;
    padding: 5px 15px;
    position: absolute;
    z-index: 98;
    width: 220px;
}

.progress3:hover:before {
    border: solid;
    border-color: #333 transparent;
    border-width: 6px 6px 0 6px;
    bottom: 20px;
    content: "";
    left: 50%;
    position: absolute;
    z-index: 99;
}


来源:https://stackoverflow.com/questions/19746767/hide-title-from-tooltip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!