【问题标题】:Hide title from tooltip从工具提示中隐藏标题
【发布时间】:2013-11-13 20:02:00
【问题描述】:

我正在使用 CSS 制作工具提示。现在使用下面的html代码

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

以及下面的 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;
}

现在它可以工作了,当我将鼠标悬停在它上面时会显示工具提示,但它也会显示标题... 如何删除下图中橙色圈出的内容。

【问题讨论】:

标签: html css tooltip edit


【解决方案1】:

只需不要通过title 属性添加内容,将其更改为data-tooltip 之类的内容。

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

jsFiddle example

您可以使用 JS/jQuery,但鉴于您采用的方法,在保留功能的同时隐藏/删除它是不可能的,因为您将无法通过 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;
}

【讨论】:

  • 属性名称tooltip在所有HTML版本中都无效,并且在未来的某些版本中可能会获得一些含义(与您的使用不兼容)。推荐的方式是使用data-*属性,比如data-tooltip,来避免此类问题。
  • @JukkaK.Korpela 感谢您的积极意见,完全忘记了这一点,谢谢 - 我会更新它。
  • 谢谢 JoshC 和 @JukkaK.Korpela,是的,Josh 您能否按照您的说法编辑您的答案,以便我确保我做的正确。谢谢大家。
  • 不使用title属性对SEO有影响,不是吗?
猜你喜欢
  • 1970-01-01
  • 2019-02-22
  • 2010-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多