0
[data-title] {
    position: relative;
    cursor: help;
}
[data-title]:hover::before {
    content: attr(data-title);
    position: absolute;
    top: -30px;
    left: 0;
    display: inline-block;
    padding: 3px 6px;
    border-radius: 2px;
    background-color: cadetblue;
    color: #fff;
    font-size: 12px;
    font-family: sans-serif;
    white-space: nowrap;
}
[data-title]:hover::after {
    content: '';
    position: absolute;
    top: -7px;
    left: 8px;
    display: inline-block;
    border: 8px solid transparent;
    border-top: 8px solid cadetblue;
}

It works with most elements Example:

<p data-title="This is the tooltips">Test Tooltips</p>

But it doesn't work with < input > element:

<input type="text" data-title="Test input tooltips" />
s k
  • 4,342
  • 3
  • 42
  • 61

1 Answers1

3

try like this

[data-title] {
    position: relative;
    cursor: help;
    margin-top:50px;
}
[data-title]:hover::before {
    content: attr(data-title);
    position: absolute;
    top: -30px;
    left: 0;
    display: inline-block;
    padding: 3px 6px;
    border-radius: 2px;
    background-color: cadetblue;
    color: #fff;
    font-size: 12px;
    font-family: sans-serif;
    white-space: nowrap;
}
[data-title]:hover::after {
    content: '';
    position: absolute;
    top: -7px;
    left: 8px;
    display: inline-block;
    border: 8px solid transparent;
    border-top: 8px solid cadetblue;
}
<div data-title="Test input tooltips">
    <input type="text" />
</div>
Bhavik Hirani
  • 1,996
  • 4
  • 28
  • 46