Skip to content

Instantly share code, notes, and snippets.

@ttristan
Last active March 23, 2018 08:20
Show Gist options
  • Save ttristan/fab8f12258bc904bbca2b8010a31f194 to your computer and use it in GitHub Desktop.
Save ttristan/fab8f12258bc904bbca2b8010a31f194 to your computer and use it in GitHub Desktop.
// HTML
<button data-tooltip="example">Example</button>
// CSS
[data-tooltip] {
position: relative;
z-index: 2;
cursor: pointer;
}
/* Hide tooltip */
[data-tooltip]:before,
[data-tooltip]:after {
visibility: hidden;
opacity: 0;
pointer-events: none;
}
/* Position tooltip above the element */
[data-tooltip]:before {
position: absolute;
bottom: 150%;
left: 50%;
margin-bottom: 5px;
margin-left: -80px;
padding: 7px;
width: 160px;
border-radius: 3px;
background-color: #000;
background-color: hsla(0, 0%, 20%, 0.9);
color: #fff;
content: attr(data-tooltip);
text-align: center;
font-size: 14px;
line-height: 1.2;
}
/* Triangle */
[data-tooltip]:after {
position: absolute;
bottom: 150%;
left: 50%;
margin-left: -5px;
width: 0;
border-top: 5px solid #000;
border-top: 5px solid hsla(0, 0%, 20%, 0.9);
border-right: 5px solid transparent;
border-left: 5px solid transparent;
content: " ";
font-size: 0;
line-height: 0;
}
/* Show tooltip */
[data-tooltip]:hover:before,
[data-tooltip]:hover:after {
visibility: visible;
opacity: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment