10

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.

enter image description here

Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
aled2305
  • 132
  • 1
  • 1
  • 6
  • 1
    Unfortunately, not possible with CSS: http://stackoverflow.com/questions/13626231/how-can-you-hide-the-title-tag-using-css – Paulie_D Nov 02 '13 at 21:10

1 Answers1

21

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;
}
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
  • 1
    Attribute name `tooltip` is invalid in all versions of HTML and may get some meaning (incompatible with your use of it) in some future version. The recommended way is to use `data-*` attributes, such as `data-tooltip`, to avoid such problems. – Jukka K. Korpela Nov 02 '13 at 21:50
  • @JukkaK.Korpela Appreciate your positive input, completely forgot about that, thanks - I will update it. – Josh Crozier Nov 02 '13 at 21:51
  • Thank You JoshC and @JukkaK.Korpela and yes Josh could you please edit your answer as you says so that I can make sure that I do it correct. Thanks guys. – aled2305 Nov 02 '13 at 21:53
  • Not using the title attribute has SEO implications, no? – Craig Tullis Sep 24 '15 at 01:54