CSS-only TOOLTIPs
by AndreaLigios
HTML
<div>Standard div, no tooltip here</div>
<div data-tooltip="Hi, I'm a tooltip. Pretty easy uh ? ;)">Div with standard tooltip. Hover me to see the tooltip.
<br/>Hovering the tooltip doesn't matter:
<br/>if you hover out of my boundaries, the tooltip will disappear.</div>
<div data-tooltip="Hi, I'm a persistent tooltip. I won't disappear when hovering me even if out of my parent boundaries. I'll also prevent other tooltips to fire :)" data-tooltip-persistent>Div with persistent tooltip. Hover me to see the tooltip.
<br/>The tooltip won't expire until you hover on me OR it.</div>
CSS
[data-tooltip]:before {
/* needed - do not touch */
content: attr(data-tooltip);
position: absolute;
opacity: 0;
/* customizable */
transition: all 0.15s ease;
padding: 10px;
color: #333;
border-radius: 10px;
box-shadow: 2px 2px 1px silver;
}
[data-tooltip]:hover:before {
/* needed - do not touch */
opacity: 1;
/* customizable */
background: yellow;
margin-top: -50px;
margin-left: 20px;
}
[data-tooltip]:not([data-tooltip-persistent]):before {
pointer-events: none;
}
/* FOR TEST PURPOSES ONLY */
div {
border: 1px solid silver;
background: #ddd;
margin: 20px;
padding: 10px;
}